#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <numeric>
#include <functional>
#include <chrono>
#include <utility>
#include <iomanip>
#include <assert.h>
using namespace std;
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
// #define int long long
rng_init;
const int MXN = 1e5 + 5, INF = 1e9 + 5;
int N, M, K;
vector<pair<int, int>> g[MXN];
int dijkstra(const vector<int> &src, const vector<int> &sink) {
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
vector<int> dist(N, INF);
for (const auto &x : src) {
dist[x] = 0;
pq.emplace(0, x);
}
vector<bool> finish(N, false);
for (const auto &x : sink)
finish[x] = true;
while (!pq.empty()) {
auto cur = pq.top();
pq.pop();
int u = cur.second, cur_dist = cur.first;
if (cur_dist > dist[u]) continue;
if (finish[u])
return cur_dist;
for (const auto &[v, wt] : g[u]) {
int new_dist = cur_dist + wt;
if (new_dist < dist[v]) {
dist[v] = new_dist;
pq.emplace(new_dist, v);
}
}
}
int ans = INF;
for (const auto &x : sink)
ans = min(ans, dist[x]);
return ans;
}
void solve() {
cin >> N >> M >> K;
for (int i = 0; i < M; i++) {
int u, v, w;
cin >> u >> v >> w;
u--, v--;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
vector<int> special(K);
for (auto &x : special) {
cin >> x;
x--;
}
int ans = INF;
while (clock() < 5.5 * CLOCKS_PER_SEC) {
shuffle(all(special), rng);
vector<int> src[2], sink[2];
for (int i = 0; i < K; i++) {
if (i < K / 4) src[0].push_back(special[i]);
else if (i < K / 2) sink[0].push_back(special[i]);
else if (i < 3 * K / 4) src[1].push_back(special[i]);
else sink[1].push_back(special[i]);
}
ans = min(ans, dijkstra(src[0], sink[0]) + dijkstra(src[1], sink[1]));
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
// cin >> TC;
while (TC--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5500 ms |
2796 KB |
Output is correct |
2 |
Correct |
5500 ms |
2796 KB |
Output is correct |
3 |
Correct |
5500 ms |
2668 KB |
Output is correct |
4 |
Correct |
5500 ms |
2744 KB |
Output is correct |
5 |
Correct |
5500 ms |
2796 KB |
Output is correct |
6 |
Correct |
5500 ms |
2748 KB |
Output is correct |
7 |
Correct |
5500 ms |
2668 KB |
Output is correct |
8 |
Correct |
5500 ms |
2788 KB |
Output is correct |
9 |
Correct |
5500 ms |
2744 KB |
Output is correct |
10 |
Correct |
5500 ms |
2744 KB |
Output is correct |
11 |
Correct |
5500 ms |
2748 KB |
Output is correct |
12 |
Correct |
5500 ms |
2796 KB |
Output is correct |
13 |
Correct |
5500 ms |
2788 KB |
Output is correct |
14 |
Correct |
5500 ms |
2828 KB |
Output is correct |
15 |
Correct |
5500 ms |
2800 KB |
Output is correct |
16 |
Correct |
5500 ms |
2752 KB |
Output is correct |
17 |
Correct |
5500 ms |
2784 KB |
Output is correct |
18 |
Correct |
5500 ms |
2752 KB |
Output is correct |
19 |
Correct |
5500 ms |
2804 KB |
Output is correct |
20 |
Correct |
5500 ms |
2768 KB |
Output is correct |
21 |
Correct |
5500 ms |
2668 KB |
Output is correct |
22 |
Correct |
5500 ms |
2748 KB |
Output is correct |
23 |
Correct |
5500 ms |
2828 KB |
Output is correct |
24 |
Correct |
5500 ms |
2752 KB |
Output is correct |
25 |
Correct |
5500 ms |
2752 KB |
Output is correct |
26 |
Correct |
5500 ms |
2752 KB |
Output is correct |
27 |
Correct |
5500 ms |
2748 KB |
Output is correct |
28 |
Correct |
5500 ms |
2924 KB |
Output is correct |
29 |
Correct |
5500 ms |
2924 KB |
Output is correct |
30 |
Correct |
5500 ms |
2804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5500 ms |
2796 KB |
Output is correct |
2 |
Correct |
5500 ms |
2796 KB |
Output is correct |
3 |
Correct |
5500 ms |
2668 KB |
Output is correct |
4 |
Correct |
5500 ms |
2744 KB |
Output is correct |
5 |
Correct |
5500 ms |
2796 KB |
Output is correct |
6 |
Correct |
5500 ms |
2748 KB |
Output is correct |
7 |
Correct |
5500 ms |
2668 KB |
Output is correct |
8 |
Correct |
5500 ms |
2788 KB |
Output is correct |
9 |
Correct |
5500 ms |
2744 KB |
Output is correct |
10 |
Correct |
5500 ms |
2744 KB |
Output is correct |
11 |
Correct |
5500 ms |
2748 KB |
Output is correct |
12 |
Correct |
5500 ms |
2796 KB |
Output is correct |
13 |
Correct |
5500 ms |
2788 KB |
Output is correct |
14 |
Correct |
5500 ms |
2828 KB |
Output is correct |
15 |
Correct |
5500 ms |
2800 KB |
Output is correct |
16 |
Correct |
5500 ms |
2752 KB |
Output is correct |
17 |
Correct |
5500 ms |
2784 KB |
Output is correct |
18 |
Correct |
5500 ms |
2752 KB |
Output is correct |
19 |
Correct |
5500 ms |
2804 KB |
Output is correct |
20 |
Correct |
5500 ms |
2768 KB |
Output is correct |
21 |
Correct |
5500 ms |
2668 KB |
Output is correct |
22 |
Correct |
5500 ms |
2748 KB |
Output is correct |
23 |
Correct |
5500 ms |
2828 KB |
Output is correct |
24 |
Correct |
5500 ms |
2752 KB |
Output is correct |
25 |
Correct |
5500 ms |
2752 KB |
Output is correct |
26 |
Correct |
5500 ms |
2752 KB |
Output is correct |
27 |
Correct |
5500 ms |
2748 KB |
Output is correct |
28 |
Correct |
5500 ms |
2924 KB |
Output is correct |
29 |
Correct |
5500 ms |
2924 KB |
Output is correct |
30 |
Correct |
5500 ms |
2804 KB |
Output is correct |
31 |
Correct |
5500 ms |
2772 KB |
Output is correct |
32 |
Correct |
5500 ms |
2784 KB |
Output is correct |
33 |
Correct |
5500 ms |
2668 KB |
Output is correct |
34 |
Correct |
5500 ms |
2796 KB |
Output is correct |
35 |
Correct |
5500 ms |
2668 KB |
Output is correct |
36 |
Correct |
5500 ms |
2924 KB |
Output is correct |
37 |
Correct |
5500 ms |
3052 KB |
Output is correct |
38 |
Correct |
5500 ms |
2924 KB |
Output is correct |
39 |
Correct |
5500 ms |
5484 KB |
Output is correct |
40 |
Correct |
5500 ms |
3636 KB |
Output is correct |
41 |
Correct |
5500 ms |
2796 KB |
Output is correct |
42 |
Correct |
5500 ms |
3528 KB |
Output is correct |
43 |
Correct |
5500 ms |
2896 KB |
Output is correct |
44 |
Correct |
5500 ms |
2924 KB |
Output is correct |
45 |
Correct |
5500 ms |
2796 KB |
Output is correct |
46 |
Correct |
5500 ms |
5540 KB |
Output is correct |
47 |
Correct |
5500 ms |
3240 KB |
Output is correct |
48 |
Correct |
5500 ms |
5564 KB |
Output is correct |
49 |
Correct |
5500 ms |
5484 KB |
Output is correct |
50 |
Correct |
5500 ms |
2668 KB |
Output is correct |
51 |
Correct |
5500 ms |
2924 KB |
Output is correct |
52 |
Correct |
5500 ms |
2816 KB |
Output is correct |
53 |
Correct |
5500 ms |
4332 KB |
Output is correct |
54 |
Correct |
5500 ms |
5484 KB |
Output is correct |
55 |
Correct |
5500 ms |
2796 KB |
Output is correct |
56 |
Correct |
5500 ms |
2668 KB |
Output is correct |
57 |
Correct |
5500 ms |
2796 KB |
Output is correct |
58 |
Correct |
5500 ms |
5464 KB |
Output is correct |
59 |
Correct |
5500 ms |
2752 KB |
Output is correct |
60 |
Correct |
5500 ms |
2924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5505 ms |
5928 KB |
Output is correct |
2 |
Correct |
5501 ms |
3612 KB |
Output is correct |
3 |
Correct |
5551 ms |
65580 KB |
Output is correct |
4 |
Correct |
5536 ms |
33084 KB |
Output is correct |
5 |
Correct |
5521 ms |
10004 KB |
Output is correct |
6 |
Correct |
5509 ms |
8492 KB |
Output is correct |
7 |
Correct |
5531 ms |
10744 KB |
Output is correct |
8 |
Correct |
5509 ms |
6116 KB |
Output is correct |
9 |
Correct |
5512 ms |
7732 KB |
Output is correct |
10 |
Correct |
5510 ms |
6572 KB |
Output is correct |
11 |
Correct |
5549 ms |
67824 KB |
Output is correct |
12 |
Correct |
5504 ms |
7012 KB |
Output is correct |
13 |
Correct |
5547 ms |
21880 KB |
Output is correct |
14 |
Correct |
5509 ms |
10008 KB |
Output is correct |
15 |
Correct |
5563 ms |
66808 KB |
Output is correct |
16 |
Correct |
5509 ms |
5752 KB |
Output is correct |
17 |
Correct |
5526 ms |
48252 KB |
Output is correct |
18 |
Correct |
5501 ms |
3684 KB |
Output is correct |
19 |
Correct |
5536 ms |
66916 KB |
Output is correct |
20 |
Correct |
5509 ms |
9364 KB |
Output is correct |
21 |
Correct |
5507 ms |
9172 KB |
Output is correct |
22 |
Correct |
5505 ms |
6504 KB |
Output is correct |
23 |
Correct |
5503 ms |
4972 KB |
Output is correct |
24 |
Correct |
5550 ms |
56992 KB |
Output is correct |
25 |
Correct |
5508 ms |
8036 KB |
Output is correct |
26 |
Correct |
5506 ms |
6372 KB |
Output is correct |
27 |
Correct |
5507 ms |
7612 KB |
Output is correct |
28 |
Correct |
5502 ms |
4836 KB |
Output is correct |
29 |
Correct |
5513 ms |
12860 KB |
Output is correct |
30 |
Correct |
5519 ms |
21892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5500 ms |
2796 KB |
Output is correct |
2 |
Correct |
5500 ms |
2796 KB |
Output is correct |
3 |
Correct |
5500 ms |
2668 KB |
Output is correct |
4 |
Correct |
5500 ms |
2744 KB |
Output is correct |
5 |
Correct |
5500 ms |
2796 KB |
Output is correct |
6 |
Correct |
5500 ms |
2748 KB |
Output is correct |
7 |
Correct |
5500 ms |
2668 KB |
Output is correct |
8 |
Correct |
5500 ms |
2788 KB |
Output is correct |
9 |
Correct |
5500 ms |
2744 KB |
Output is correct |
10 |
Correct |
5500 ms |
2744 KB |
Output is correct |
11 |
Correct |
5500 ms |
2748 KB |
Output is correct |
12 |
Correct |
5500 ms |
2796 KB |
Output is correct |
13 |
Correct |
5500 ms |
2788 KB |
Output is correct |
14 |
Correct |
5500 ms |
2828 KB |
Output is correct |
15 |
Correct |
5500 ms |
2800 KB |
Output is correct |
16 |
Correct |
5500 ms |
2752 KB |
Output is correct |
17 |
Correct |
5500 ms |
2784 KB |
Output is correct |
18 |
Correct |
5500 ms |
2752 KB |
Output is correct |
19 |
Correct |
5500 ms |
2804 KB |
Output is correct |
20 |
Correct |
5500 ms |
2768 KB |
Output is correct |
21 |
Correct |
5500 ms |
2668 KB |
Output is correct |
22 |
Correct |
5500 ms |
2748 KB |
Output is correct |
23 |
Correct |
5500 ms |
2828 KB |
Output is correct |
24 |
Correct |
5500 ms |
2752 KB |
Output is correct |
25 |
Correct |
5500 ms |
2752 KB |
Output is correct |
26 |
Correct |
5500 ms |
2752 KB |
Output is correct |
27 |
Correct |
5500 ms |
2748 KB |
Output is correct |
28 |
Correct |
5500 ms |
2924 KB |
Output is correct |
29 |
Correct |
5500 ms |
2924 KB |
Output is correct |
30 |
Correct |
5500 ms |
2804 KB |
Output is correct |
31 |
Correct |
5500 ms |
2772 KB |
Output is correct |
32 |
Correct |
5500 ms |
2784 KB |
Output is correct |
33 |
Correct |
5500 ms |
2668 KB |
Output is correct |
34 |
Correct |
5500 ms |
2796 KB |
Output is correct |
35 |
Correct |
5500 ms |
2668 KB |
Output is correct |
36 |
Correct |
5500 ms |
2924 KB |
Output is correct |
37 |
Correct |
5500 ms |
3052 KB |
Output is correct |
38 |
Correct |
5500 ms |
2924 KB |
Output is correct |
39 |
Correct |
5500 ms |
5484 KB |
Output is correct |
40 |
Correct |
5500 ms |
3636 KB |
Output is correct |
41 |
Correct |
5500 ms |
2796 KB |
Output is correct |
42 |
Correct |
5500 ms |
3528 KB |
Output is correct |
43 |
Correct |
5500 ms |
2896 KB |
Output is correct |
44 |
Correct |
5500 ms |
2924 KB |
Output is correct |
45 |
Correct |
5500 ms |
2796 KB |
Output is correct |
46 |
Correct |
5500 ms |
5540 KB |
Output is correct |
47 |
Correct |
5500 ms |
3240 KB |
Output is correct |
48 |
Correct |
5500 ms |
5564 KB |
Output is correct |
49 |
Correct |
5500 ms |
5484 KB |
Output is correct |
50 |
Correct |
5500 ms |
2668 KB |
Output is correct |
51 |
Correct |
5500 ms |
2924 KB |
Output is correct |
52 |
Correct |
5500 ms |
2816 KB |
Output is correct |
53 |
Correct |
5500 ms |
4332 KB |
Output is correct |
54 |
Correct |
5500 ms |
5484 KB |
Output is correct |
55 |
Correct |
5500 ms |
2796 KB |
Output is correct |
56 |
Correct |
5500 ms |
2668 KB |
Output is correct |
57 |
Correct |
5500 ms |
2796 KB |
Output is correct |
58 |
Correct |
5500 ms |
5464 KB |
Output is correct |
59 |
Correct |
5500 ms |
2752 KB |
Output is correct |
60 |
Correct |
5500 ms |
2924 KB |
Output is correct |
61 |
Correct |
5505 ms |
5928 KB |
Output is correct |
62 |
Correct |
5501 ms |
3612 KB |
Output is correct |
63 |
Correct |
5551 ms |
65580 KB |
Output is correct |
64 |
Correct |
5536 ms |
33084 KB |
Output is correct |
65 |
Correct |
5521 ms |
10004 KB |
Output is correct |
66 |
Correct |
5509 ms |
8492 KB |
Output is correct |
67 |
Correct |
5531 ms |
10744 KB |
Output is correct |
68 |
Correct |
5509 ms |
6116 KB |
Output is correct |
69 |
Correct |
5512 ms |
7732 KB |
Output is correct |
70 |
Correct |
5510 ms |
6572 KB |
Output is correct |
71 |
Correct |
5549 ms |
67824 KB |
Output is correct |
72 |
Correct |
5504 ms |
7012 KB |
Output is correct |
73 |
Correct |
5547 ms |
21880 KB |
Output is correct |
74 |
Correct |
5509 ms |
10008 KB |
Output is correct |
75 |
Correct |
5563 ms |
66808 KB |
Output is correct |
76 |
Correct |
5509 ms |
5752 KB |
Output is correct |
77 |
Correct |
5526 ms |
48252 KB |
Output is correct |
78 |
Correct |
5501 ms |
3684 KB |
Output is correct |
79 |
Correct |
5536 ms |
66916 KB |
Output is correct |
80 |
Correct |
5509 ms |
9364 KB |
Output is correct |
81 |
Correct |
5507 ms |
9172 KB |
Output is correct |
82 |
Correct |
5505 ms |
6504 KB |
Output is correct |
83 |
Correct |
5503 ms |
4972 KB |
Output is correct |
84 |
Correct |
5550 ms |
56992 KB |
Output is correct |
85 |
Correct |
5508 ms |
8036 KB |
Output is correct |
86 |
Correct |
5506 ms |
6372 KB |
Output is correct |
87 |
Correct |
5507 ms |
7612 KB |
Output is correct |
88 |
Correct |
5502 ms |
4836 KB |
Output is correct |
89 |
Correct |
5513 ms |
12860 KB |
Output is correct |
90 |
Correct |
5519 ms |
21892 KB |
Output is correct |
91 |
Correct |
5518 ms |
9504 KB |
Output is correct |
92 |
Correct |
5537 ms |
82448 KB |
Output is correct |
93 |
Correct |
5509 ms |
13476 KB |
Output is correct |
94 |
Correct |
5528 ms |
48640 KB |
Output is correct |
95 |
Correct |
5501 ms |
3816 KB |
Output is correct |
96 |
Correct |
5501 ms |
3932 KB |
Output is correct |
97 |
Correct |
5510 ms |
16760 KB |
Output is correct |
98 |
Correct |
5511 ms |
9524 KB |
Output is correct |
99 |
Correct |
5508 ms |
10216 KB |
Output is correct |
100 |
Correct |
5552 ms |
88116 KB |
Output is correct |
101 |
Correct |
5520 ms |
45212 KB |
Output is correct |
102 |
Correct |
5521 ms |
44200 KB |
Output is correct |
103 |
Correct |
5563 ms |
63356 KB |
Output is correct |
104 |
Correct |
5529 ms |
67200 KB |
Output is correct |
105 |
Correct |
5508 ms |
7268 KB |
Output is correct |
106 |
Correct |
5546 ms |
63976 KB |
Output is correct |
107 |
Correct |
5518 ms |
24600 KB |
Output is correct |
108 |
Correct |
5507 ms |
12424 KB |
Output is correct |
109 |
Correct |
5502 ms |
5192 KB |
Output is correct |
110 |
Correct |
5503 ms |
6800 KB |
Output is correct |
111 |
Correct |
5508 ms |
12728 KB |
Output is correct |
112 |
Correct |
5535 ms |
89080 KB |
Output is correct |
113 |
Correct |
5542 ms |
89664 KB |
Output is correct |
114 |
Correct |
5552 ms |
12392 KB |
Output is correct |
115 |
Correct |
5549 ms |
45488 KB |
Output is correct |
116 |
Correct |
5538 ms |
81092 KB |
Output is correct |
117 |
Correct |
5563 ms |
62048 KB |
Output is correct |
118 |
Correct |
5552 ms |
55632 KB |
Output is correct |
119 |
Correct |
5550 ms |
71276 KB |
Output is correct |
120 |
Correct |
5521 ms |
48104 KB |
Output is correct |