题意:给一个无向图,求从结点1到其他结点的最短路中的长度最大值
思路:裸的Dijkstra……记得先cin>>n再初始化,居然在这个弱智错误上卡了10分钟。atoi()在数字与字符混合输入这种情况好用,用来将一个字符串转为整型。
struct node {
LL d;
int u;
bool operator < (const node& k) const {
return d > k.d;
}
};
struct Edge {
int from, to;
LL dis;
Edge(int u,int v,LL d):from(u),to(v),dis(d){}
};
int n, m;
int p[maxn];
vector<Edge> Edges;
vector<int> G[maxn];
bool done[maxn];
LL d[maxn];
void solve(){
cin >> n;
memset(done, false, sizeof(done));
memset(p, 0, sizeof(p));
memset(d, 0, sizeof(d));
Edges.clear();
for (int i = 0; i <= n; i++) G[i].clear();
for (int i = 1; i <= n; i++) { d[i] = (i == 1 ? 0 : INF);}
Edges.push_back(Edge(0, 0, 0));
int num = 0;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i - 1; j++) {
char ch[9];
cin >> ch;
LL d;
if (ch[0] != 'x')
{
d = atoi(ch);
Edges.push_back(Edge(i, j, d));
G[i].push_back(++num);
Edges.push_back(Edge(j, i, d));
G[j].push_back(++num);
}
}
}
priority_queue<node> Q;
Q.push(node{ 0, 1 });
while (!Q.empty()) {
node x = Q.top(); Q.pop();
int u = x.u;
if (done[u]) continue;
for (int i = 0; i < G[u].size(); i++) {
Edge& e = Edges[G[u][i]];
if (d[u] + e.dis < d[e.to]) {
d[e.to] = d[u] + e.dis;
p[e.to] = G[u][i];
Q.push(node{ d[e.to],e.to });
}
}
done[u] = true;
}
LL ans = -1;
for (int i = 2; i <= n; i++) ans = max(ans, d[i]);
cout << ans;
}