HDU 2544 ( 最短路 )
程序员文章站
2022-06-07 14:44:37
...
Problem : 2544 ( 最短路 ) Judge Status : Accepted RunId : 6260505 Language : C++ Author : ssun Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta #include "iostream" #define N 2000000 using namespace std; int main(){ int n,m; int floyd[110][110]; while(cin>>n>>m){ if(n==0 && m==0) break; int i,j,k; for(i=1; i<=n; i++){ for(j=1; j<=n; j++){ floyd[i][j] = N; } floyd[i][i] = 0; } int a,b,c; for(i=0; i<m; i++){ cin>>a>>b>>c; if(floyd[a][b] > c){ floyd[a][b] = c; floyd[b][a] = c; } } for(k=1; k<=n; k++){ for(i=1; i<=n; i++){ for(j=i+1; j<=n; j++){ if(floyd[i][k]+floyd[k][j] < floyd[i][j]){ floyd[i][j] = floyd[i][k] + floyd[k][j]; floyd[j][i] = floyd[i][j]; } } } } cout<<floyd[1][n]<<endl; } return 0; }
//第一次做最短路,参考别人的
推荐阅读