Main topic:
I'll give you the N-point T-Bar, and find the shortest n->1.
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 1002Ten One structEdge A { - inte, W; - }; the -Vector<edge> g[1002]; - BOOLVIS[MAXN]; - intDIST[MAXN], N, m;; + - voidInit () + { A for(intI=0; i<=n; i++) at { - g[i].clear (); -Dist[i] =INF; -Vis[i] =false; - } - } in intSPFA () - { to Edge P, Pn; +Queue<edge>Q; -P.E = N, p.w =0; theDist[n] =0; * Q.push (P); $ Panax Notoginseng while( !q.empty ()) - { theP =Q.front (); + Q.pop (); A theVIS[P.E] =false; + intLen =g[p.e].size (); - $ for(intI=0; i<len; i++) $ { -Pn =G[p.e][i]; - the if(DIST[PN.E] > DIST[P.E] +PN.W) - {WuyiDIST[PN.E] = DIST[P.E] +PN.W; the - if( !VIS[PN.E]) Wu { - Q.push (Pn); AboutVIS[PN.E] =true; $ } - } - } - } A returndist[1]; + } the intMain () - { $ Edge P; the the while(Cin >> M >>N) the { the Init (); - for(intI=0; i<m; i++) in { the intA, B, C; the Aboutscanf"%d%d%d",&a,&b,&c); the theP.E = B, p.w =C; the G[a].push_back (P); +P.E =A; - G[b].push_back (P); the }Bayi the intAns =SPFA (); the -cout << ans <<Endl; - } the return 0; the}
POJ 2387 Til the cows Come Home