标签:bool tle fun imp atom contain ali puts continue
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 4542 Accepted Submission(s): 1436
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 #include<algorithm> 6 #include<map> 7 #include<set> 8 #include<vector> 9 #include<functional> 10 using namespace std; 11 #define LL long long 12 #define pli pair<long long,int> 13 #define mp make_pair 14 #define inf 0x7fffffffffffff 15 struct Edge{ 16 int v,w,next; 17 }e[2000010]; 18 int first[1100005]; 19 int tot,n,m; 20 void add(int u,int v,int w){ 21 e[tot].v=v; 22 e[tot].w=w; 23 e[tot].next=first[u]; 24 first[u]=tot++; 25 } 26 bool vis[1100005]; 27 LL d1[1100005],d2[1100005]; 28 void dij(int s,LL d[]){ 29 memset(vis,0,sizeof(vis)); 30 int tot_n=n+m+10; 31 for(int i=0;i<=tot_n;++i) d[i]=inf; 32 priority_queue<pli,vector<pli>,greater<pli> >q; 33 q.push(mp(0,s)); 34 d[s]=0; 35 while(!q.empty()){ 36 int u=q.top().second; 37 q.pop(); 38 if(vis[u]) continue; 39 vis[u]=1; 40 for(int i=first[u];i+1;i=e[i].next){ 41 if(d[e[i].v]>d[u]+e[i].w){ 42 d[e[i].v]=d[u]+e[i].w; 43 q.push(mp(d[e[i].v],e[i].v)); 44 } 45 } 46 } 47 } 48 int main() 49 { 50 int t,i,j,k; 51 int cas=0; 52 cin>>t; 53 while(t--){int ti,si,a; 54 memset(first,-1,sizeof(first)); 55 tot=0; 56 cin>>n>>m; 57 for(i=1;i<=m;++i){ 58 scanf("%d%d",&ti,&si); 59 while(si--){ 60 scanf("%d",&a); 61 add(a,n+i,ti); 62 add(n+i,a,ti); 63 } 64 } 65 printf("Case #%d: ",++cas); 66 dij(1,d1); 67 dij(n,d2); 68 LL mint=inf; 69 for(i=1;i<=n;++i){ 70 mint=min(mint,max(d1[i],d2[i])); 71 } 72 if(mint==inf){ 73 puts("Evil John"); 74 } 75 else{ 76 cout<<mint/2<<endl; 77 for(i=1;i<=n;++i){ 78 if(mint==max(d1[i],d2[i])){ 79 printf("%d",i); 80 break; 81 } 82 } 83 i++; 84 for(;i<=n;++i){ 85 if(mint==max(d1[i],d2[i])){ 86 printf(" %d",i); 87 } 88 } 89 puts(""); 90 } 91 } 92 return 0; 93 }
标签:bool tle fun imp atom contain ali puts continue
原文地址:https://www.cnblogs.com/zzqc/p/8824124.html