-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc1602.cpp
More file actions
54 lines (49 loc) · 1.45 KB
/
icpc1602.cpp
File metadata and controls
54 lines (49 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using pint = pair<int, int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, q;
const int limit = 987654321;
vector<pint> bother;
vector<vector<int> > dist, maxBother;
cin >> n >> m >> q;
bother.resize(n + 1);
dist.resize(n + 1, vector<int>(n + 1, limit));
maxBother.resize(n + 1, vector<int>(n + 1, limit));
for (int i = 1; i <= n; i++) {
cin >> bother[i].first;
bother[i].second = i;
dist[i][i] = 0;
maxBother[i][i] = bother[i].first;
}
for (int i = 0; i < m; i++) {
int u, v, t;
cin >> u >> v >> t;
dist[u][v] = dist[v][u] = t;
}
sort(bother.begin(), bother.end());
for (int k = 1; k <= n; k++) {
int s = bother[k].second;
int b = bother[k].first;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][s] + dist[s][j]);
maxBother[i][j] =
min(maxBother[i][j],
max(dist[i][j] + max(maxBother[i][i], maxBother[j][j]),
dist[i][s] + dist[s][j] + b));
}
}
}
for (int i = 0; i < q; i++) {
int u, v;
cin >> u >> v;
cout << ((maxBother[u][v] < limit) ? maxBother[u][v] : -1) << '\n';
}
return 0;
}