提交时间:2023-02-03 17:15:03
运行 ID: 68267
#include<bits/stdc++.h> using namespace std; const int N=210,INF=1e9; int n,m; int ans[N][N]; void floyd(){ for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ ans[i][j]=min(ans[i][j],ans[i][k]+ans[k][j]); } } } } int main(){ while(cin>>n>>m){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i==j) ans[i][j]=0; else ans[i][j]=INF; } } for(int i=1;i<=m;i++){ int a,b,c; cin>>a>>b>>c; ans[a][b]=min(ans[a][b],c); ans[b][a]=min(ans[b][a],c); } floyd(); int a,b; cin>>a>>b; if(ans[a][b]>INF/2) cout<<"No path"<<endl; else cout<<ans[a][b]<<endl; } return 0; }