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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int T, n, m, t, u, v, w, i, s, g, h, v1, v2, a1, c, d[2002];
bool b[2002];
priority_queue<pair<int, int>> p;
priority_queue<int, vector<int>, greater<int>> q;
int main() {
cin >> T;
while (T--) {
cin >> n >> m >> t;
vector<vector<pair<int, int>>> a(n + 1);
cin >> s >> g >> h;
for (i = 0; i < m; i++) {
cin >> u >> v >> w;
a[u].push_back({ v,w });
a[v].push_back({ u,w });
if ((u == g && v == h) || (u == h && v == g))
a1 = w;
}
fill(d, d + n + 1, 3000000);
fill(b, b + n + 1, 0);
d[s] = 0;
p.push({ 0, s });
while (!p.empty()) {
w = p.top().second;
p.pop();
if (b[w]) continue;
b[w] = true;
for (auto t : a[w]) {
u = t.first, v = t.second;
if (d[u] > d[w] + v) {
d[u] = d[w] + v;
p.push({ -d[u], u });
}
}
}
v1 = d[g] + a1;
v2 = d[h] + a1;
for (i = 0; i < t; i++) {
cin >> c;
fill(d, d + n + 1, 3000000);
fill(b, b + n + 1, 0);
d[c] = 0;
p.push({ 0, c });
while (!p.empty()) {
w = p.top().second;
p.pop();
if (b[w]) continue;
b[w] = true;
for (auto t : a[w]) {
u = t.first, v = t.second;
if (d[u] > d[w] + v) {
d[u] = d[w] + v;
p.push({ -d[u], u });
}
}
}
if (v1 + d[h] == d[s] || v2 + d[g] == d[s])
q.push(c);
}
while (!q.empty()) {
cout << q.top() << " ";
q.pop();
}
cout << endl;
}
}
|