SPFA water problem. Record the maximum load capacity to this node. Because of a small error and WA a night, sad, t_t ...
#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<algorithm>using namespacestd;Const intmaxn= ++Ten;structedge{int from, To,w;} e[1000010];intDis[maxn],vis[maxn];vector<Edge>G[MAXN];intN,m,tot;voidSPFA () {Queue<int>p; memset (DIS,0,sizeof(DIS)); memset (Vis,0,sizeof(VIS)); vis[1]=1; Q.push (1); while(!Q.empty ()) { intH=q.front (); Q.pop (); vis[h]=0; for(intI=0; I<g[h].size (); i++) {Edge&e=G[h][i]; if(h==1) {dis[e.to]=E.W; Q.push (e.to); Vis[e.to]=1; } Else { if(min (DIS[H],E.W) >Dis[e.to]) {Dis[e.to]=min (DIS[H],E.W); if(vis[e.to]==0) {Q.push (e.to); Vis[e.to]=1; } } } } }}intMain () {intr,t; scanf ("%d",&R); for(t=1; t<=r; t++) {scanf ("%d%d",&n,&m); Tot=0; for(intI=0; i<=n;i++) g[i].clear (); while(m--) { int from, To,w; scanf ("%d%d%d",& from,&to,&W); E[tot]. from= from; e[tot].to=to;e[tot].w=W; G[e[tot]. from].push_back (E[tot]); Tot++; E[tot]. from=to;e[tot].to= from; e[tot].w=W; G[e[tot]. from].push_back (E[tot]); Tot++; } SPFA (); printf ("Scenario #%d:\n", T); printf ("%d\n", Dis[n]); printf ("\ n"); } return 0;}
POJ 1797 Heavy Transportation