HDU 5521 Meeting

Source: Internet
Author: User

ACM/ICPC Shenyang Station live race m question

Shortest circuit

Set N+M nodes, the first n nodes are blocks, the second node is set, and the points in each set set are connected to the set, and the shortest path is obtained from 1 and n respectively. Pay attention to explode Int.

#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<algorithm>using namespacestd;Const Long Longinf=1e16;Const intmaxn=200000+Ten;Const intmaxm=5000000+Ten;Long LongDIS1[MAXN],DIS2[MAXN],VAL[MAXN];BOOLFlag1[maxn],flag2[maxn];vector<int>G[maxn];vector<int>Ans;structedge{int  from; intto ;} E[MAXM];intT,n,m,tot;voidinit () {memset (Val,0,sizeofval); memset (Flag1,0,sizeofFlag1);  for(intI=0; i<maxn;i++) dis1[i]=INF; memset (Flag2,0,sizeofFlag2);  for(intI=0; i<maxn;i++) dis2[i]=INF;  for(intI=0; i<maxn;i++) g[i].clear ();    Ans.clear (); Tot=0;}voidAddedge (intXinty) {Tot++; E[tot]. from=x; E[tot].to=y;    G[x].push_back (TOT); Tot++; E[tot]. from=y; E[tot].to=x; G[y].push_back (tot);}voidspfa1 () {Queue<int>Q; Q.push (1); flag1[1]=1;d is1[1]=0;  while(!Q.empty ()) {        intH=q.front (); Q.pop (); flag1[h]=0;  for(intI=0; I<g[h].size (); i++)        {            intId=G[h][i]; if(dis1[h]+val[e[id].to]<Dis1[e[id].to]) {Dis1[e[id].to]=dis1[h]+Val[e[id].to]; if(flag1[e[id].to]==0) {flag1[e[id].to]=1;                Q.push (e[id].to); }            }        }    }}voidspfa2 () {Queue<int>p; Q.push (n); Flag2[n]=1;d is2[n]=0;  while(!Q.empty ()) {        intH=q.front (); Q.pop (); flag2[h]=0;  for(intI=0; I<g[h].size (); i++)        {            intId=G[h][i]; if(dis2[h]+val[e[id].to]<Dis2[e[id].to]) {Dis2[e[id].to]=dis2[h]+Val[e[id].to]; if(flag2[e[id].to]==0) {flag2[e[id].to]=1;                Q.push (e[id].to); }            }        }    }}intMain () {scanf ("%d",&T);  for(intCase=1; case<=t; case++) {init (); scanf ("%d%d",&n,&m);  for(intI=1; i<=m;i++)        {            intS,x;Long LongT; scanf ("%lld%d",&t,&s); Val[n+i]=T;  for(intj=1; j<=s;j++) {scanf ("%d",&x); Addedge (X,n+i);        }} spfa1 ();        SPFA2 (); Long Longans=INF;  for(intI=1; i<=n;i++)        {            if(dis1[i]==inf| | Dis2[i]==inf)Continue; if(Max (Dis1[i],dis2[i]) <ans) ans=Max (dis1[i],dis2[i]); } printf ("Case #%d:", case); if(Ans==inf) printf ("Evil john\n"); Else{printf ("%lld\n", ans);  for(intI=1; i<=n;i++)            {                if(dis1[i]==inf| | Dis2[i]==inf)Continue; if(Max (dis1[i],dis2[i]) = =ans)            Ans.push_back (i); }             for(intI=0; I<ans.size (); i++) {printf ("%d", Ans[i]); if(I<ans.size ()-1) printf (" "); Elseprintf"\ n"); }        }    }    return 0;}

HDU 5521 Meeting

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.