标签:style color os io for 代码 size ios
高仿代码如下
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
#define N 205
int d[N][N];
void floyd(int n){
for(int k = 0;k < n;k++)
for(int i = 0;i < n;i++)
for(int j = 0;j < n;j++){
if(d[i][j] > d[i][k]+d[j][k])
d[i][j] = d[i][k]+d[j][k];
}
}
int main(){
int n,m,a,b,x;
//freopen("test.txt","r",stdin);
while(cin>>n>>m){
memset(d,0x3f,sizeof(d));
for(int i=0;i<m;i++){
cin>>a>>b>>x;
d[a][b]=d[b][a]=min(d[a][b],x);
}
for(int i=0;i<n;i++)d[i][i]=0;
cin>>a>>b;
floyd(n);
if(d[a][b]!=inf)cout<<d[a][b]<<endl;
else cout<<"-1"<<endl;
}
return 0;
}
HDU 1847(floyd),布布扣,bubuko.com
标签:style color os io for 代码 size ios
原文地址:http://www.cnblogs.com/Mr-Xu-JH/p/3874256.html