0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 06:18:48 +00:00

P2966 [USACO09DEC]Cow Toll Paths G

R53073231
This commit is contained in:
Baoshuo Ren 2021-07-14 11:03:24 +08:00 committed by Baoshuo Ren
parent 5fb9cb25ce
commit 7afce147b3
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,39 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, q, u, v, w, s, t, f[255][255], ans[255][255];
pair<int, int> c[255];
int main() {
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = i == j ? 0 : 0x3f3f3f3f;
ans[i][j] = 0x3f3f3f3f;
}
}
for (int i = 1; i <= n; i++) {
cin >> c[i].first;
c[i].second = i;
}
sort(c + 1, c + 1 + n);
for (int i = 1; i <= m; i++) {
cin >> u >> v >> w;
f[u][v] = min(f[u][v], w);
f[v][u] = min(f[u][v], w);
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[c[i].second][c[j].second] = min(f[c[i].second][c[j].second], f[c[i].second][c[k].second] + f[c[k].second][c[j].second]);
ans[c[i].second][c[j].second] = min(ans[c[i].second][c[j].second], f[c[i].second][c[j].second] + max({c[i].first, c[j].first, c[k].first}));
}
}
}
for (int i = 1; i <= q; i++) {
cin >> s >> t;
cout << ans[s][t] << endl;
}
return 0;
}