# hdu 2544 最短路

Problem Description

Input

Output

Sample Input
2 1
1 2 3
3 3
1 2 5
2 3 5
3 1 2
0 0

Sample Output
3
2

Source

 1 #include <stdio.h>
2 #include <string.h>
3 #include <math.h>
4 #include <limits.h>
5 #include <algorithm>
6 #include <iostream>
7 #include <ctype.h>
8 #include <iomanip>
9 #include <queue>
10 #include <map>
11 #include <stdlib.h>
12 using namespace std;
13
14 #define INF 99999999
15
16 int main()
17 {
18     int e[101][101];
19     int n,m,a,b,c,i,j,k;
20     while(~scanf("%d %d",&n,&m)&&n!=0&&m!=0){
21         for(i=1;i<=n;i++)
22             for(j=1;j<=n;j++)
23                 e[i][j]=INF;
24         while(m--){
25             scanf("%d%d%d",&a,&b,&c);
26
27                 e[b][a]=e[a][b]=c;
28
29         }
30         for(k=1;k<=n;k++){  //Floyd核心算法...
31             for(i=1;i<=n;i++){
32                 for(j=1;j<=n;j++){
33                     if(e[i][j]>e[i][k]+e[k][j])
34                         e[i][j]=e[i][k]+e[k][j];
35                 }
36             }
37         }
38
39         printf("%d\n",e[1][n]);
40     }
41 }