1 /**2 Test Instructions: There are n points, M sets3 The time of Point 22 in the collection is Ti;4 There are two people in the 1,n, the output of the minimum meeting time, and what points (can walk and stop);5 6 Idea: * * * Abstract a collection as a point. A collection that has been visited is no longer accessible. 7 the set abstract point of the collection. 8 which collection the belong belongs to. 9 */Ten#include <bits/stdc++.h> One using namespacestd; AtypedefLong Longll; - Constll INF =0x7f7f7f7f; -typedef pair<int,int> P;//First is the shortest distance, second is the vertex number the structedge{ - intto ; - intCost ; - }; +Vector<edge> g[100005]; -ll d1[100005],d2[100005],t[100005]; + intsetsize[100005]; A BOOLvis[100005]; at BOOLvisset[100005]; - intv,e,n,m; -vector<int> belong[100005]; -vector<int> set[100005]; - voidDijkstraintS,LL *d) { -priority_queue<p,vector<p>,greater<p> >que; in for(inti =1; I <= N; i + +) d[i] =INF; -memset (Vis,false,sizeof(Vis)); tomemset (Visset,false,sizeof(Visset)); +D[s] =0; -Que.push (P (0, s)); the while(!Que.empty ()) { *P p =que.top (); Que.pop (); $ intU =P.second;Panax Notoginseng //if (D[u] < P.first) continue; - if(Vis[u])Continue; theVis[u] =true; + /* A for (int i = 0; i < g[u].size (); i + +) { the edge& e = g[u][i]; + if (d[e.to] > D[u] + e.cost) { - d[e.to] = D[u] + e.cost; $ Que.push (P (d[e.to],e.to)); $ } - } - */ the for(inti =0; I < belong[u].size (); i + +) {//What collections do you belong to - intSt =Belong[u][i];Wuyi if(Visset[st])Continue; theVISSET[ST] =true; - for(intj =0; J < Setsize[st]; J + +){ Wu intv =Set[st][j]; - if(U = = v)Continue; About if(D[v] > D[u] +T[st]) { $D[V] = D[u] +T[st]; - Que.push (P (d[v],v)); - } - } A } + } the } - $ voidinit () { thescanf"%d%d",&n,&m); the for(inti =0; I <= N; i + +) belong[i].clear (); the for(inti =0; I <= m; i + +) set[i].clear (); the for(inti =0; I < m; i + +){ -scanf"%lld%d",&t[i],&setsize[i]); in for(intj =0; J < Setsize[i]; J + +){ the inttmp; thescanf"%d",&tmp); AboutSet[i].push_back (TMP);//the points within the collection. theBelong[tmp].push_back (i);//which collections belong to. the } the } + } - voidSolveintKase) { theDijkstra1, D1);Bayi Dijkstra (N,D2); thell ans =0x7f7f7f7f; the for(inti =1; I <= N; i + +){ -Ans =min (Ans,max (d1[i],d2[i)); - } the if(ans = =0x7f7f7f7f) printf ("Case #%d:evil john\n", Kase); the Else{ theprintf"Case #%d:%d\n", Kase,ans); the BOOLf =false; - for(inti =1; I <= N; i + +){ the if(ans = =Max (D1[i],d2[i])) { the if(f) printf (" "); theprintf"%d", i);94f =true; the } the } theprintf"\ n");98 } About - 101 }102 103 intMain () {104 intT; thescanf"%d",&T);106 for(inti =1; I <= T; i + +){107 init ();108 solve (i);109 } the return 0;111}
HDU 5521 Meeting (good title, shortest way, 2015ACM/ICPC Asia Shenyang Station)