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)