#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <queue>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn=105;
int m;
struct edge//每条边的 终点, 权值
{
int end;
int d;
edge(){}
edge(int a,int b){end=a,d=b;}
bool operator<(const edge& a)const
{
return d>a.d;
}
};
vector <edge> eg[maxn]; //eg[i]是第i个点的连接所有边的数组
bool vis[maxn];
int dis[maxn];
int n;
char s[4];
void dijkstra()
{
memset(vis,false,sizeof(vis));
memset(dis,0x3f,sizeof(dis));
dis[1]=0;
priority_queue <edge> q;//装满边的有限队列
int maxx=-INF;
q.push(edge(1,dis[1]));//把一个到第一个点距离为0的边放在队列中
while(!q.empty()&&m--)
{
edge now=q.top(); q.pop();
if(vis[now.end]) continue;
vis[now.end]=true;
//cout<<now.d<<' '<<eg[now.end].size()<<endl;
for(int i=0;i<eg[now.end].size();i++)//循环该边的终点连接的边数次
{
edge y=eg[now.end][i];//y是该点连接的第i条边
if(dis[y.end]>now.d+y.d){
dis[y.end]=now.d+y.d;
q.push(edge(y.end,dis[y.end]));
}
}
}
for(int i=1;i<=n;i++)
maxx=max(maxx,dis[i]);
cout<<maxx<<endl;
}
int main()
{
//freopen("input.txt","r",stdin);
cin>>n;
m=0;
for(int i=2;i<=n;i++)
for(int j=1;j<i;j++)
{
scanf("%s",s);
if(s[0]=='x') continue;
int t;
sscanf(s,"%d",&t);
m++;
eg[i].push_back(edge(j,t));
eg[j].push_back(edge(i,t));
}
dijkstra();
return 0;
}
邻接表敲得我很伤啊...
还能再优化吗......