Hangzhou Electric 2544--Shortest Way (Floyd)

Source: Internet
Author: User

Shortest circuit

Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 41510 Accepted Submission (s): 18133


Problem description in the annual school game, all the students who enter the finals will get a very beautiful T-shirt. But every time our staff put demonstrating clothes from the store back to the game, it was very tiring! So now they want to find the shortest route from the store to the arena, can you help them?

Input inputs include multiple sets of data. The first row of each group of data is two integers n, m (n<=100,m<=10000), n indicates that there are several intersections on the streets of Chengdu, the intersection labeled 1 is the location of the store, the intersection labeled N is the location of the stadium, M said there are several roads in Chengdu. N=m=0 indicates the end of the input. The next m line, each line consists of 3 integers a,b,c (1<=a,b<=n,1<=c<=1000), indicating that there is a road between junction A and intersection B, and our staff needs C minutes to walk this road.
Enter a guarantee that there are at least 1 shops to the track.

Output one line for each set of inputs, indicating the shortest time the worker has walked from the store to the arena

Sample Input2 1 1 2 3 3 3 1 2 5 2 3 5 3 1 2 0 0

Sample OUTPUT3 2

SOURCEUESTC 6th Programming Contest Online

Recommendlcy | We have carefully selected several similar problems for you:2066 1217 2112 1142 1548
1#include <cstdio>2#include <iostream>3 using namespacestd;4 5 Const intINF =0x3f3f3f3f;6 7 intmap[ the][ the];8 intI, J, K, N, M;9 Ten voidFloyd () One { A      for(k=1; k<=n; k++) -          for(i=1; i<=n; i++) -              for(j=1; j<=n; J + +) the                 if(Map[i][j] > Map[i][k] +Map[k][j]) -MAP[I][J] = Map[i][k] +Map[k][j]; -printf"%d\n", map[1][n]); - } + intMain () - { +      while(~SCANF ("%d%d", &n, &m)) A     { at         if(n==0&& m==0) -          Break; -          for(i=1; i<=n; i++) -              for(j=1; j<=n; J + +) -MAP[I][J] = (i==j?0: INF); -         intu, V, W; in          for(i=1; i<=m; i++){ -scanf" %d%d%d", &u, &v, &W); to             if(Map[u][v] >W) +map[u][v]=map[v][u]=W; -         } the Floyd (); *     } $     return 0;Panax Notoginseng}

Hangzhou Electric 2544--Shortest Way (Floyd)

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.