#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include<cmath>
#include<stdlib.h>
#include<sstream>
using namespace std;
const int maxn=101;
const int INF=0x3f3f3f3f;
stringstream sstd;
int map[maxn][maxn];
int main(){
int n;cin>>n;
memset(map, INF, sizeof(map));
for(int i=1;i<=n;i++){
int a;string s;
for(int j=1;j<i;j++){
cin>>s;
if(s=="x")continue;
sstd<<s;
sstd>>a;
sstd.str("");
sstd.clear();
map[i][j]=map[j][i]=a;
}
}
//floyd ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
}
}
}
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
int ac=0;
for(int i=2;i<=n;i++){
ac=max(ac,map[1][i]);
}
cout<<ac<<endl;
return 0;
}
/*第一行表示5个村子,接下来是邻接矩阵,对角线一下的部分;最后输出第一个村子到其他每一个的最短路的最大值
5
50
30 5
100 20 50
10 x x 10
*/
floyd 任意两点最短路
最新推荐文章于 2024-08-02 04:21:55 发布