Invitation Cards
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2300 Accepted Submission(s): 1119
The transport system is very special: all lines are unidirectional and connect exactly two stops. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g. X:00 or X:30, where 'X' denotes the hour. The fee for transport between two stops is given by special tables and is payable on the spot. The lines are planned in such a way, that each round trip (i.e. a journey starting and finishing at the same stop) passes through a Central Checkpoint Stop (CCS) where each passenger has to pass a thorough check including body scan.
All the ACM student members leave the CCS each morning. Each volunteer is to move to one predetermined stop to invite passengers. There are as many volunteers as stops. At the end of the day, all students travel back to CCS. You are to write a computer program that helps ACM to minimize the amount of money to pay every day for the transport of their employees.
2 2 2 1 2 13 2 1 33 4 6 1 2 10 2 1 60 1 3 20 3 4 10 2 4 5 4 1 50
46 210

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
const int maxn=1000002;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
struct node
{
int v,w,next;
}edge1[maxn],edge2[maxn];
int pre1[maxn];
int pre2[maxn];
int n,m;
int dist[maxn];
int vis[maxn];
ll ans;
void init()
{
memset(pre1,-1,sizeof(pre1));
memset(pre2,-1,sizeof(pre2));
int index1=1,index2=1;
int i,j,flag;
int x,y,w;
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&w);
edge1[index1].v=y;
edge1[index1].w=w;
edge1[index1].next=pre1[x];
pre1[x]=index1++;
edge2[index2].v=x;
edge2[index2].w=w;
edge2[index2].next=pre2[y];
pre2[y]=index2++;
}
}
void spfa(int *pre,node *edge)
{
int start=1;
//int end=n;
queue <int>q;
cle(vis);
fill(dist+1,dist+1+maxn,INF);
dist[start]=0;
vis[start]=1;
q.push(start);
while(!q.empty())
{
int top=q.front();///边的起点
q.pop();
vis[top]=0;
for(int j=pre[top];j!=-1;j=edge[j].next)
{
int e=edge[j].v;///边的终点
if(dist[e]>edge[j].w+dist[top])
{
dist[e]=edge[j].w+dist[top];
if(!vis[e])
{
q.push(e);
vis[e]=1;
}
}
}
}
for(int i=2;i<=n;i++)
ans+=dist[i];
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--)
{
ans=0;
cin>>n>>m;
init();
spfa(pre1,edge1);
spfa(pre2,edge2);
cout<<ans<<endl;
}
return 0;
}