0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 07:31:59 +00:00

P2888 [USACO07NOV]Cow Hurdles S

R53028439
This commit is contained in:
Baoshuo Ren 2021-07-13 18:55:39 +08:00 committed by Baoshuo Ren
parent 6d72585647
commit e90aeb21d7
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, t, s, e, h, a, b, f[305][305];
int main() {
cin >> n >> m >> t;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = i == j ? 0 : INT_MAX;
}
}
for (int i = 1; i <= m; i++) {
cin >> s >> e >> h;
f[s][e] = h;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = min(f[i][j], max(f[i][k], f[k][j]));
}
}
}
for (int i = 0; i < t; i++) {
cin >> a >> b;
cout << (f[a][b] == INT_MAX ? -1 : f[a][b]) << endl;
}
return 0;
}