#include<iostream> #include<cstring> #include<algorithm> #include<iomanip> #include<cmath> #include<cstdio> #include<vector> using namespace std; #define MAXN 101 #define INF 0x3f3f3f3f /* 8:19 8:35 题意理解太慢:在所有最短路路中间一条最长的 8:52 sscanf用法 8:57 忘记BEEN,g[i][j] = g[j][i]双向 */ int n; bool been[MAXN]; int g[MAXN][MAXN],lowcost[MAXN]; int Dijkstra() { memset(lowcost,INF,sizeof(lowcost)); memset(been,false,sizeof(been)); lowcost[1] = 0; for(int j=0;j<n;j++) { int Min = INF,k = -1; for(int i=1;i<=n;i++) { if(!been[i]&&lowcost[i]<Min) { Min = lowcost[i]; k = i; } } if(k==-1) break; been[k] = true; for(int i=1;i<=n;i++) { if(!been[i]&&lowcost[i]>lowcost[k]+g[k][i]) { lowcost[i] = lowcost[k]+g[k][i]; } } } int Max = -1; for(int i=1;i<=n;i++) { Max = max(Max,lowcost[i]); } return Max; } int main() { cin>>n; char s[30]; memset(g,INF,sizeof(g)); for(int i=1;i<=n;i++) { for(int j=1;j<i;j++) { cin>>s; if(s[0]=='x') { g[i][j] = g[j][i]= INF; } else { sscanf(s,"%d",&g[i][j]); g[j][i] = g[i][j]; } } } int ans =Dijkstra(); cout<<ans<<endl; return 0; }