链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=989
题意&题解:
紫书P365
代码:
31 int c, s, q; 32 int d[MAXN][MAXN]; 33 34 int main() { 35 ios::sync_with_stdio(false), cin.tie(0); 36 int cas = 1; 37 while (cin >> c >> s >> q, c) { 38 memset(d, 0x3f, sizeof(d)); 39 while (s--) { 40 int u, v, w; 41 cin >> u >> v >> w; 42 d[u][v] = d[v][u] = w; 43 } 44 rep(k, 1, c + 1) rep(i, 1, c + 1) rep(j, 1, c + 1) 45 d[i][j] = min(d[i][j], max(d[i][k], d[k][j])); 46 if (cas != 1) cout << endl; 47 cout << "Case #" << cas++ << endl; 48 while (q--) { 49 int s, t; 50 cin >> s >> t; 51 if (d[s][t] == INF) cout << "no path" << endl; 52 else cout << d[s][t] << endl; 53 } 54 } 55 return 0; 56 }
时间: 2024-10-06 06:15:04