floyd算法与dijkstra算法的区别就是在floyd算法中可以有限负权边

while(cin>>n>>m){
for(int i = 0;i < n;i++)
for(int j = 0;j < n;j++){
if(i == j) dp[i][j] = 0;
else dp[i][j] = 1e9;
}
while(m--){
cin>>x>>y>>z;
dp[x][y] = min(dp[x][y],z);
dp[y][x] = min(dp[y][x],z);
}
cin>>s>>t;
for(int k = 0;k < n;k++)
for(int i = 0;i < n;i++)
for(int j = 0;j < n;j++)
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
if(dp[s][t] == 1e9) cout<<"-1"<<endl;
else cout<<dp[s][t]<<endl;
}