POJ 2387 Til the cows Come Home

Source: Internet
Author: User

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

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.