#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl '\n'
const int INF = 1e15;
const int MOD = 1e9+7;
const int MXN = 1e5+9;
vector<array<int,2>> g[MXN];
int n, m, k;
int magic(vector<int> &s, vector<int> &f) {
priority_queue<array<int,2>, vector<array<int,2>>, greater<array<int,2>>> pq;
vector<bool> inf(n, 0);
for (int i : s) pq.push({0, i});
for (int i : f) inf[i] = 1;
vector<bool> vis(n, 0);
while (!pq.empty()) {
auto u = pq.top();
pq.pop();
if (vis[u[1]]) continue;
vis[u[1]] = 1;
if (inf[u[1]]) return u[0];
for (auto v : g[u[1]]) if (!vis[v[1]]) {
pq.push({u[0] + v[0], v[1]});
}
}
return INF;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
cin>>n>>m>>k;
for (int i = 0; i < m; i++) {
int a, b, wt; cin>>a>>b>>wt;
--a, --b;
g[a].push_back({wt,b});
g[b].push_back({wt,a});
}
vector<int> special(k);
for (int &i : special) cin>>i, --i;
int ans = INF;
while (clock() < 5.5*CLOCKS_PER_SEC) {
shuffle(special.begin(), special.end(), rng);
vector<int> start1, finish1, start2, finish2;
for (int i = 0; i < k; i++) {
if (i < k/4) start1.push_back(special[i]);
else if (i < k/2) finish1.push_back(special[i]);
else if (i < 3*k/4) start2.push_back(special[i]);
else finish2.push_back(special[i]);
}
int d = 0;
d += magic(start1, finish1);
d += magic(start2, finish2);
ans = min(d, ans);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5500 ms |
2688 KB |
Output is correct |
2 |
Correct |
5500 ms |
2860 KB |
Output is correct |
3 |
Correct |
5500 ms |
2748 KB |
Output is correct |
4 |
Correct |
5500 ms |
2796 KB |
Output is correct |
5 |
Correct |
5500 ms |
2748 KB |
Output is correct |
6 |
Correct |
5500 ms |
2796 KB |
Output is correct |
7 |
Correct |
5500 ms |
2860 KB |
Output is correct |
8 |
Correct |
5500 ms |
2860 KB |
Output is correct |
9 |
Correct |
5500 ms |
2744 KB |
Output is correct |
10 |
Correct |
5500 ms |
2748 KB |
Output is correct |
11 |
Correct |
5500 ms |
2796 KB |
Output is correct |
12 |
Correct |
5500 ms |
2704 KB |
Output is correct |
13 |
Correct |
5500 ms |
2856 KB |
Output is correct |
14 |
Correct |
5500 ms |
2840 KB |
Output is correct |
15 |
Correct |
5500 ms |
2856 KB |
Output is correct |
16 |
Correct |
5500 ms |
2668 KB |
Output is correct |
17 |
Correct |
5500 ms |
2924 KB |
Output is correct |
18 |
Correct |
5500 ms |
2796 KB |
Output is correct |
19 |
Correct |
5500 ms |
2924 KB |
Output is correct |
20 |
Correct |
5500 ms |
2668 KB |
Output is correct |
21 |
Correct |
5500 ms |
2820 KB |
Output is correct |
22 |
Correct |
5500 ms |
2796 KB |
Output is correct |
23 |
Correct |
5500 ms |
2800 KB |
Output is correct |
24 |
Correct |
5500 ms |
2752 KB |
Output is correct |
25 |
Correct |
5500 ms |
2748 KB |
Output is correct |
26 |
Correct |
5500 ms |
2752 KB |
Output is correct |
27 |
Correct |
5500 ms |
2872 KB |
Output is correct |
28 |
Correct |
5500 ms |
2796 KB |
Output is correct |
29 |
Correct |
5500 ms |
2876 KB |
Output is correct |
30 |
Correct |
5500 ms |
2880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5500 ms |
2688 KB |
Output is correct |
2 |
Correct |
5500 ms |
2860 KB |
Output is correct |
3 |
Correct |
5500 ms |
2748 KB |
Output is correct |
4 |
Correct |
5500 ms |
2796 KB |
Output is correct |
5 |
Correct |
5500 ms |
2748 KB |
Output is correct |
6 |
Correct |
5500 ms |
2796 KB |
Output is correct |
7 |
Correct |
5500 ms |
2860 KB |
Output is correct |
8 |
Correct |
5500 ms |
2860 KB |
Output is correct |
9 |
Correct |
5500 ms |
2744 KB |
Output is correct |
10 |
Correct |
5500 ms |
2748 KB |
Output is correct |
11 |
Correct |
5500 ms |
2796 KB |
Output is correct |
12 |
Correct |
5500 ms |
2704 KB |
Output is correct |
13 |
Correct |
5500 ms |
2856 KB |
Output is correct |
14 |
Correct |
5500 ms |
2840 KB |
Output is correct |
15 |
Correct |
5500 ms |
2856 KB |
Output is correct |
16 |
Correct |
5500 ms |
2668 KB |
Output is correct |
17 |
Correct |
5500 ms |
2924 KB |
Output is correct |
18 |
Correct |
5500 ms |
2796 KB |
Output is correct |
19 |
Correct |
5500 ms |
2924 KB |
Output is correct |
20 |
Correct |
5500 ms |
2668 KB |
Output is correct |
21 |
Correct |
5500 ms |
2820 KB |
Output is correct |
22 |
Correct |
5500 ms |
2796 KB |
Output is correct |
23 |
Correct |
5500 ms |
2800 KB |
Output is correct |
24 |
Correct |
5500 ms |
2752 KB |
Output is correct |
25 |
Correct |
5500 ms |
2748 KB |
Output is correct |
26 |
Correct |
5500 ms |
2752 KB |
Output is correct |
27 |
Correct |
5500 ms |
2872 KB |
Output is correct |
28 |
Correct |
5500 ms |
2796 KB |
Output is correct |
29 |
Correct |
5500 ms |
2876 KB |
Output is correct |
30 |
Correct |
5500 ms |
2880 KB |
Output is correct |
31 |
Correct |
5500 ms |
2796 KB |
Output is correct |
32 |
Correct |
5500 ms |
2792 KB |
Output is correct |
33 |
Correct |
5500 ms |
2812 KB |
Output is correct |
34 |
Correct |
5500 ms |
2768 KB |
Output is correct |
35 |
Correct |
5500 ms |
2752 KB |
Output is correct |
36 |
Correct |
5500 ms |
3092 KB |
Output is correct |
37 |
Correct |
5500 ms |
3388 KB |
Output is correct |
38 |
Correct |
5500 ms |
2824 KB |
Output is correct |
39 |
Correct |
5501 ms |
11204 KB |
Output is correct |
40 |
Correct |
5500 ms |
4340 KB |
Output is correct |
41 |
Correct |
5500 ms |
2828 KB |
Output is correct |
42 |
Correct |
5500 ms |
4352 KB |
Output is correct |
43 |
Correct |
5500 ms |
3008 KB |
Output is correct |
44 |
Correct |
5500 ms |
2828 KB |
Output is correct |
45 |
Correct |
5500 ms |
2760 KB |
Output is correct |
46 |
Correct |
5502 ms |
10480 KB |
Output is correct |
47 |
Correct |
5500 ms |
4016 KB |
Output is correct |
48 |
Correct |
5501 ms |
9748 KB |
Output is correct |
49 |
Correct |
5501 ms |
9816 KB |
Output is correct |
50 |
Correct |
5500 ms |
2812 KB |
Output is correct |
51 |
Correct |
5500 ms |
2828 KB |
Output is correct |
52 |
Correct |
5500 ms |
2812 KB |
Output is correct |
53 |
Correct |
5500 ms |
6472 KB |
Output is correct |
54 |
Correct |
5501 ms |
10280 KB |
Output is correct |
55 |
Correct |
5500 ms |
2668 KB |
Output is correct |
56 |
Correct |
5500 ms |
2768 KB |
Output is correct |
57 |
Correct |
5500 ms |
2944 KB |
Output is correct |
58 |
Correct |
5501 ms |
10444 KB |
Output is correct |
59 |
Correct |
5500 ms |
2796 KB |
Output is correct |
60 |
Correct |
5500 ms |
2996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5505 ms |
8204 KB |
Output is correct |
2 |
Correct |
5500 ms |
3436 KB |
Output is correct |
3 |
Correct |
5535 ms |
151524 KB |
Output is correct |
4 |
Correct |
5549 ms |
69424 KB |
Output is correct |
5 |
Correct |
5553 ms |
17848 KB |
Output is correct |
6 |
Correct |
5511 ms |
13436 KB |
Output is correct |
7 |
Correct |
5520 ms |
19536 KB |
Output is correct |
8 |
Correct |
5505 ms |
8132 KB |
Output is correct |
9 |
Correct |
5507 ms |
12656 KB |
Output is correct |
10 |
Correct |
5507 ms |
9820 KB |
Output is correct |
11 |
Correct |
5604 ms |
157188 KB |
Output is correct |
12 |
Correct |
5509 ms |
10360 KB |
Output is correct |
13 |
Correct |
5524 ms |
50688 KB |
Output is correct |
14 |
Correct |
5515 ms |
16568 KB |
Output is correct |
15 |
Correct |
5553 ms |
154716 KB |
Output is correct |
16 |
Correct |
5509 ms |
7148 KB |
Output is correct |
17 |
Correct |
5535 ms |
97536 KB |
Output is correct |
18 |
Correct |
5501 ms |
3424 KB |
Output is correct |
19 |
Correct |
5535 ms |
138128 KB |
Output is correct |
20 |
Correct |
5515 ms |
15680 KB |
Output is correct |
21 |
Correct |
5514 ms |
15484 KB |
Output is correct |
22 |
Correct |
5507 ms |
9280 KB |
Output is correct |
23 |
Correct |
5503 ms |
5776 KB |
Output is correct |
24 |
Correct |
5574 ms |
131448 KB |
Output is correct |
25 |
Correct |
5514 ms |
12740 KB |
Output is correct |
26 |
Correct |
5505 ms |
7948 KB |
Output is correct |
27 |
Correct |
5511 ms |
10696 KB |
Output is correct |
28 |
Correct |
5502 ms |
4528 KB |
Output is correct |
29 |
Correct |
5524 ms |
18600 KB |
Output is correct |
30 |
Correct |
5520 ms |
32116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5500 ms |
2688 KB |
Output is correct |
2 |
Correct |
5500 ms |
2860 KB |
Output is correct |
3 |
Correct |
5500 ms |
2748 KB |
Output is correct |
4 |
Correct |
5500 ms |
2796 KB |
Output is correct |
5 |
Correct |
5500 ms |
2748 KB |
Output is correct |
6 |
Correct |
5500 ms |
2796 KB |
Output is correct |
7 |
Correct |
5500 ms |
2860 KB |
Output is correct |
8 |
Correct |
5500 ms |
2860 KB |
Output is correct |
9 |
Correct |
5500 ms |
2744 KB |
Output is correct |
10 |
Correct |
5500 ms |
2748 KB |
Output is correct |
11 |
Correct |
5500 ms |
2796 KB |
Output is correct |
12 |
Correct |
5500 ms |
2704 KB |
Output is correct |
13 |
Correct |
5500 ms |
2856 KB |
Output is correct |
14 |
Correct |
5500 ms |
2840 KB |
Output is correct |
15 |
Correct |
5500 ms |
2856 KB |
Output is correct |
16 |
Correct |
5500 ms |
2668 KB |
Output is correct |
17 |
Correct |
5500 ms |
2924 KB |
Output is correct |
18 |
Correct |
5500 ms |
2796 KB |
Output is correct |
19 |
Correct |
5500 ms |
2924 KB |
Output is correct |
20 |
Correct |
5500 ms |
2668 KB |
Output is correct |
21 |
Correct |
5500 ms |
2820 KB |
Output is correct |
22 |
Correct |
5500 ms |
2796 KB |
Output is correct |
23 |
Correct |
5500 ms |
2800 KB |
Output is correct |
24 |
Correct |
5500 ms |
2752 KB |
Output is correct |
25 |
Correct |
5500 ms |
2748 KB |
Output is correct |
26 |
Correct |
5500 ms |
2752 KB |
Output is correct |
27 |
Correct |
5500 ms |
2872 KB |
Output is correct |
28 |
Correct |
5500 ms |
2796 KB |
Output is correct |
29 |
Correct |
5500 ms |
2876 KB |
Output is correct |
30 |
Correct |
5500 ms |
2880 KB |
Output is correct |
31 |
Correct |
5500 ms |
2796 KB |
Output is correct |
32 |
Correct |
5500 ms |
2792 KB |
Output is correct |
33 |
Correct |
5500 ms |
2812 KB |
Output is correct |
34 |
Correct |
5500 ms |
2768 KB |
Output is correct |
35 |
Correct |
5500 ms |
2752 KB |
Output is correct |
36 |
Correct |
5500 ms |
3092 KB |
Output is correct |
37 |
Correct |
5500 ms |
3388 KB |
Output is correct |
38 |
Correct |
5500 ms |
2824 KB |
Output is correct |
39 |
Correct |
5501 ms |
11204 KB |
Output is correct |
40 |
Correct |
5500 ms |
4340 KB |
Output is correct |
41 |
Correct |
5500 ms |
2828 KB |
Output is correct |
42 |
Correct |
5500 ms |
4352 KB |
Output is correct |
43 |
Correct |
5500 ms |
3008 KB |
Output is correct |
44 |
Correct |
5500 ms |
2828 KB |
Output is correct |
45 |
Correct |
5500 ms |
2760 KB |
Output is correct |
46 |
Correct |
5502 ms |
10480 KB |
Output is correct |
47 |
Correct |
5500 ms |
4016 KB |
Output is correct |
48 |
Correct |
5501 ms |
9748 KB |
Output is correct |
49 |
Correct |
5501 ms |
9816 KB |
Output is correct |
50 |
Correct |
5500 ms |
2812 KB |
Output is correct |
51 |
Correct |
5500 ms |
2828 KB |
Output is correct |
52 |
Correct |
5500 ms |
2812 KB |
Output is correct |
53 |
Correct |
5500 ms |
6472 KB |
Output is correct |
54 |
Correct |
5501 ms |
10280 KB |
Output is correct |
55 |
Correct |
5500 ms |
2668 KB |
Output is correct |
56 |
Correct |
5500 ms |
2768 KB |
Output is correct |
57 |
Correct |
5500 ms |
2944 KB |
Output is correct |
58 |
Correct |
5501 ms |
10444 KB |
Output is correct |
59 |
Correct |
5500 ms |
2796 KB |
Output is correct |
60 |
Correct |
5500 ms |
2996 KB |
Output is correct |
61 |
Correct |
5505 ms |
8204 KB |
Output is correct |
62 |
Correct |
5500 ms |
3436 KB |
Output is correct |
63 |
Correct |
5535 ms |
151524 KB |
Output is correct |
64 |
Correct |
5549 ms |
69424 KB |
Output is correct |
65 |
Correct |
5553 ms |
17848 KB |
Output is correct |
66 |
Correct |
5511 ms |
13436 KB |
Output is correct |
67 |
Correct |
5520 ms |
19536 KB |
Output is correct |
68 |
Correct |
5505 ms |
8132 KB |
Output is correct |
69 |
Correct |
5507 ms |
12656 KB |
Output is correct |
70 |
Correct |
5507 ms |
9820 KB |
Output is correct |
71 |
Correct |
5604 ms |
157188 KB |
Output is correct |
72 |
Correct |
5509 ms |
10360 KB |
Output is correct |
73 |
Correct |
5524 ms |
50688 KB |
Output is correct |
74 |
Correct |
5515 ms |
16568 KB |
Output is correct |
75 |
Correct |
5553 ms |
154716 KB |
Output is correct |
76 |
Correct |
5509 ms |
7148 KB |
Output is correct |
77 |
Correct |
5535 ms |
97536 KB |
Output is correct |
78 |
Correct |
5501 ms |
3424 KB |
Output is correct |
79 |
Correct |
5535 ms |
138128 KB |
Output is correct |
80 |
Correct |
5515 ms |
15680 KB |
Output is correct |
81 |
Correct |
5514 ms |
15484 KB |
Output is correct |
82 |
Correct |
5507 ms |
9280 KB |
Output is correct |
83 |
Correct |
5503 ms |
5776 KB |
Output is correct |
84 |
Correct |
5574 ms |
131448 KB |
Output is correct |
85 |
Correct |
5514 ms |
12740 KB |
Output is correct |
86 |
Correct |
5505 ms |
7948 KB |
Output is correct |
87 |
Correct |
5511 ms |
10696 KB |
Output is correct |
88 |
Correct |
5502 ms |
4528 KB |
Output is correct |
89 |
Correct |
5524 ms |
18600 KB |
Output is correct |
90 |
Correct |
5520 ms |
32116 KB |
Output is correct |
91 |
Correct |
5517 ms |
11556 KB |
Output is correct |
92 |
Correct |
5613 ms |
172452 KB |
Output is correct |
93 |
Correct |
5517 ms |
19320 KB |
Output is correct |
94 |
Correct |
5531 ms |
89504 KB |
Output is correct |
95 |
Correct |
5501 ms |
3436 KB |
Output is correct |
96 |
Correct |
5501 ms |
3692 KB |
Output is correct |
97 |
Correct |
5528 ms |
23384 KB |
Output is correct |
98 |
Correct |
5506 ms |
11588 KB |
Output is correct |
99 |
Correct |
5515 ms |
13172 KB |
Output is correct |
100 |
Correct |
5560 ms |
168352 KB |
Output is correct |
101 |
Correct |
5529 ms |
70672 KB |
Output is correct |
102 |
Correct |
5532 ms |
69748 KB |
Output is correct |
103 |
Correct |
5546 ms |
134888 KB |
Output is correct |
104 |
Correct |
5547 ms |
125172 KB |
Output is correct |
105 |
Correct |
5505 ms |
8216 KB |
Output is correct |
106 |
Correct |
5575 ms |
124716 KB |
Output is correct |
107 |
Correct |
5520 ms |
36464 KB |
Output is correct |
108 |
Correct |
5519 ms |
16500 KB |
Output is correct |
109 |
Correct |
5502 ms |
4972 KB |
Output is correct |
110 |
Correct |
5504 ms |
7388 KB |
Output is correct |
111 |
Correct |
5516 ms |
17092 KB |
Output is correct |
112 |
Correct |
5552 ms |
180832 KB |
Output is correct |
113 |
Correct |
5612 ms |
183896 KB |
Output is correct |
114 |
Correct |
5529 ms |
17784 KB |
Output is correct |
115 |
Correct |
5570 ms |
79052 KB |
Output is correct |
116 |
Correct |
5554 ms |
169600 KB |
Output is correct |
117 |
Correct |
5540 ms |
132232 KB |
Output is correct |
118 |
Correct |
5557 ms |
108936 KB |
Output is correct |
119 |
Correct |
5565 ms |
136456 KB |
Output is correct |
120 |
Correct |
5529 ms |
74472 KB |
Output is correct |