1 条题解
-
0
参考答案:
#include<iostream> using namespace std; const int N = 310; int d[N][N]; int n, m, k; const int INF = 0x3f3f3f3f; void floyd() { for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } int main() { cin >> n >> m >> k; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { if (i == j) d[i][j] = 0; else d[i][j] = INF; } while (m--) { int a, b, c; cin >> a >> b >> c; d[a][b] = min(d[a][b], c); } floyd(); while (k--) { int a, b; cin >> a >> b; if (d[a][b] > INF / 2) cout << "impossible" << endl; else cout << d[a][b] << endl; } return 0; }
- 1
信息
- ID
- 96
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 7
- 已通过
- 2
- 上传者