-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13424.cpp
More file actions
48 lines (48 loc) · 1.21 KB
/
13424.cpp
File metadata and controls
48 lines (48 loc) · 1.21 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
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int dist[101][101];
vector<int> fr;
int main() {
int tc; cin >> tc;
while(tc--) {
fr.clear();
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(i == j) dist[i][j] = 0;
else dist[i][j] = 12345689;
}
}
for(int i = 0; i < m; i++) {
int a, b, c; cin >> a >> b >> c;
dist[a][b] = c;
dist[b][a] = c;
}
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
cin >> k;
for(int i = 0; i < k; i++) {
int x; cin >> x;
fr.push_back(x);
}
int MIN = 123456789;
int ans;
for(int i = 1; i <= n; i++) {
int sum = 0;
for(int j = 0; j < k; j++) {
sum += dist[fr[j]][i];
}
if(sum < MIN) {
MIN = sum;
ans = i;
}
}
cout << ans << "\n";
}
}