#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> using namespace std; const int N=110; const int INF = 0x3f3f3f3f; char s[20]; int n; int f[N][N]; void init() { for(int i = 1 ; i <= n ; i++) for(int j = 1; j <= n ; j++) if(i == j) f[i][j] = 0; else f[i][j] = INF ; } void floyd() { for(int k = 1; k <= n ; k++) for(int i = 1; i <= n ; i++) for(int j = 1; j <= n ; j++) f[i][j] = min(f[i][j],f[i][k] +f[k][j]); int ans = -INF ; for(int i = 1; i <= n ; i++) if(f[1][i] !=INF) ans = max(ans,f[1][i]); cout<<ans<<endl; } int main() { cin>>n; init(); for(int i = 2; i <= n ; i++) for(int j = 1; j < i; j++) { cin>>s; if(s[0]!= ‘x‘) { int num = atoi(s); f[i][j] = f[j][i] = num; } } floyd(); return 0; }
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12235784.html
时间: 2024-10-13 16:18:07