The shortest path problem of Hangzhou electric 3790--(double-weighted minimum spanning tree)

Source: Internet
Author: User

Shortest path problem

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 17425 Accepted Submission (s): 5199


Problem description give you n points, M no edge, each side has a length D and spend P, give you the beginning of the end of T, the minimum distance from the output starting point to the end point and the cost, if the shortest distance there are multiple routes, the output cost is the least.

Input n,m, the number of the point is 1~n, then the M line, 4 numbers per line, A,b,d,p, indicates an edge between A and B, and its length is D, which costs p. The last line is two number s,t; start s, end point. N and m are 0 o'clock input end.
(1<n<=1000, 0<m<100000, s! = t)

The output line has two numbers, a minimum distance, and a cost.

Sample INPUT3 2 1 2 5 6 2 3 4 5 1 3 0 0

Sample Output9 11

SOURCE Zhejiang University Computer Postgraduate exam on the machine-2010

recommendnotonlysuccess | We have carefully selected several similar problems for you:2066 1217 2112 1142 1548 RE: The topic does not say that the cost is the least, so the distance and cost should be one by one corresponding;
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intINF =0x3f3f3f;5 intmap[1010][1010], mpa[1010][1010], dis1[1010], dis2[1010], vis[1010];6 intI, J, M, N;7 voidDijkstra (intCRA)8 {9memset (Vis,0,sizeof(Vis));Ten      for(i=1; i<=m; i++) One     { ADis1[i] =Map[cra][i]; -Dis2[i] =Mpa[cra][i]; -     } theVIS[CRA] =1; -      for(i=1; i<m; i++) -     { -         intmin = INF, temp =CRA; +          for(j=1; j<=m; J + +) -         { +             if(!vis[j] && Dis1[j] <min) A             { attemp =J; -Min =Dis1[j]; -             } -         } -Vis[temp] =1; -          for(j=1; j<=m; J + +) in         { -             if(!vis[j] && dis1[j] > Dis1[temp] +Map[temp][j]) to             { +DIS1[J] = Dis1[temp] +Map[temp][j]; -DIS2[J] = Dis2[temp] +Mpa[temp][j]; the             } *             Else if(!vis[j] && dis1[j] = = Dis1[temp] + map[temp][j] && dis2[j] > dis2[temp]+Mpa[temp][j]) $             {Panax NotoginsengDIS2[J] = Dis2[temp] +Mpa[temp][j]; -             } the         } +     } A } the intMain () + { -      while(~SCANF ("%d%d", &m, &n), m|N) $     { $          for(i=1; i<=m; i++) -          for(j=1; j<=m; J + +) -         { theMap[i][j]= (i==j?0: INF); -Mpa[i][j]= (i==j?0: INF);Wuyi         } the         intA, B, D, p; -          for(i =1; I <= N; i++) Wu         { -scanf"%d %d%d%d", &a, &b, &d, &p); About         /*if (Map[a][b] > D)//pit.!  $ Map[a][b]=map[b][a]=d; - if (Mpa[a][b] > P) - mpa[a][b]=mpa[b][a]=p; */ -             if(Map[a][b] >d) A             { +map[a][b]=map[b][a]=D; thempa[a][b]=mpa[b][a]=p; -             } $         }     the         ints, t; thescanf"%d%d", &s, &t); the Dijkstra (s); theprintf"%d%d\n", Dis1[t], dis2[t]); -     } in     return 0; the}

The shortest path problem of Hangzhou electric 3790--(double-weighted minimum spanning tree)

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.