HDU 5521 Meeting (good title, shortest way, 2015ACM/ICPC Asia Shenyang Station)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.