Main topic:
To give you a T, for the T Group test data, an n for n points, an m for the M bar, and three parameters for each edge, a,b,c indicates that the maximum bearing weight from A to B is C,
Let you find a line that requires the maximum load on this line, the smallest in all other lines.
Topic Analysis:
This problem can be solved by simply deforming the SPFA here.
First our dist array, the starting position is initialized to INF, the other locations are initialized to 0
Then we update the dist array, and the result output DIST[N] is OK.
Why write this: Because every time we want to find the smallest one of the largest sides in all the paths, there may be a write-around
Recursion is: dist[e] = min (Dist[e], Max (Dist[s], g[s][i]));
Here's the code:
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <algorithm>5#include <vector>6#include <queue>7 using namespacestd;8 #defineINF 0XFFFFFFF9 #defineMAXN 1050Ten One structEdge A { - inte; - Long LongW; the }; -Vector<edge>G[MAXN]; - Long LongDIST[MAXN]; - BOOLVIS[MAXN]; + intm, N; - Long LongSPFA () + { A Edge P, Pn; atP.E =1, P.W =0; -Queue <Edge>Q; - Q.push (P); - - while( !q.empty ()) - { inP =Q.front (); - Q.pop (); toVIS[P.E] =false; + intLen =g[p.e].size (); - the for(intI=0; i<len; i++) * { $Pn =G[p.e][i];Panax Notoginseng - if(DIST[PN.E] <min (DIST[P.E],PN.W)) the { +DIST[PN.E] =min (DIST[P.E],PN.W); A the if(!VIS[PN.E]) + { -VIS[PN.E] =true; $ Q.push (Pn); $ } - } - } the } - returnDist[n];Wuyi } the voidInit () - { Wu for(intI=1; I<=n; i++) - { About g[i].clear (); $Vis[i] =false; -Dist[i] =0; - } -dist[1] =INF; A } + intMain () the { - intT, CAS =1; $ Edge P; theCIN >>T; the the while(t--) the { -scanf"%d%d",&n,&m); in the Init (); the for(intI=0; i<m; i++) About { the intA, B, C; thescanf"%d%d%d",&a,&b,&c); theP.E = B, p.w =C; + - G[a].push_back (P); the BayiP.E =A; the the G[b].push_back (P); - } - Long LongAns =SPFA (); the theprintf"Scenario #%d:\n%lld\n", cas++, ans); the if(T) theprintf"\ n"); - the } the return 0; the}
Poj1797-heavy Transportation (maximum side, shortest path deformation SPFA)