<poj-3268> Silver Cow Party Shortest Path problem

Source: Internet
Author: User

  Link : http://poj.org/problem?id=3268

   The cows are going to the party, enter N = number of vertices (cattle field),M = number of sides (road), X = end point (Party point). Problem: The maximum value of the round trip time is asked.

Input:

Line 1:three space-separated integers, respectively: N, M, and X
Lines 2.. M+1:line I+1 describes road IWith three space-separated integers: Ai, Bi, and Ti. The described road runs from farm AiTo farm Bi, requiring TiTime units to traverse.

Output:

Line 1:one integer:the maximum of the time any one cow must walk.
   4 8 2 1 2 4 1 3 2 1 4 7 2 1 1 2 3 5 3 1 2 3 4 4 4 2 3

Sample Output:

  10

  problem-solving ideas : Because the subject is one-way, so you can do a forward graph and a reverse graph, respectively, the time to solve the back and forth, and then find the maximum value.

Here is my code:
1#include <cstring>2#include <iostream>3 #defineINF 99999994 using namespacestd;5 6 BOOLused[100005];7 intV, E;8 Const intMAXN =1005;9 Ten voidDijkstra (intSintcost[][1005],intd[]) { OneFill (d, D + V +1, INF); AFill (used,used + V +1,false); -D[s] =0; -      while(true) { the         intv =-1; -          for(intU =1; U <= V; u++) { -             if(!used[u] && (v = =-1|| D[u] < d[v])) v =u; -         } +         if(v = =-1) Break; -USED[V] =true; +          for(intU =1; U <= V; ++u) { A             if(D[u] > D[v] +Cost[v][u]) { atD[u] = D[v] +Cost[v][u]; -             } -         } -     } - } -  in intCOST[MAXN][MAXN]; - intRCOST[MAXN][MAXN]; to  + intMain () { -     intD[MAXN]; the     intRD[MAXN]; *     intx, Y, W; $     intSUM[MAXN];Panax Notoginseng     intS; -CIN >> V >> E >>S; the      +      for(inti =1; I <= V; ++i) A          for(intj =1; J <= V; ++j) theRCOST[I][J] = cost[i][j] =INF; +      -      for(inti =0; i < E; ++i) { $Cin >> x >> y >>W; $RCOST[Y][X] = Cost[x][y] =W; -     } -      theDijkstra (S, cost, D);//calculate the shortest path separately - Dijkstra (S, rcost, RD);Wuyi      the      for(inti =1; I <= V; ++i)//sum -Sum[i] = D[i] +Rd[i]; Wu      -     intMaxnum = sum[1]; About      for(inti =1; I <= V; ++i)///find the maximum value $         if(Sum[i] >maxnum) -Maxnum =Sum[i]; -      -cout << Maxnum <<Endl; A      +     return 0; the}
View Code

Welcome code friends to review, grow together.

<poj-3268> Silver Cow Party Shortest Path problem

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.