# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
556596 | 2022-05-03T11:50:13 Z | eecs | Parkovi (COCI22_parkovi) | C++17 | 1467 ms | 43496 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 200010; int n, K; ll f[maxn], g[maxn]; vector<int> res; vector<array<int, 2>> G[maxn]; int main() { scanf("%d %d", &n, &K); for (int i = 1, u, v, w; i < n; i++) { scanf("%d %d %d", &u, &v, &w); G[u].push_back({v, w}), G[v].push_back({u, w}); } auto init = [&](auto self, int u, int fa) -> void { for (int i = 0; i < G[u].size(); i++) { if (G[u][i][0] == fa) { G[u].erase(G[u].begin() + i); break; } } for (auto &e : G[u]) { self(self, e[0], u); } }; init(init, 1, 0); auto chk = [&](ll lim) { auto dfs = [&](auto self, int u) -> void { g[u] = 1e18; for (auto &e : G[u]) { self(self, e[0]); if (~f[e[0]] && f[e[0]] + e[1] > lim) res.push_back(e[0]), f[e[0]] = -1, g[e[0]] = 0; g[u] = min(g[u], g[e[0]] + e[1]); } f[u] = g[u] <= lim ? -1 : 0; for (auto &e : G[u]) { if (~f[e[0]] && f[e[0]] + e[1] + g[u] > lim) f[u] = max(f[u], f[e[0]] + e[1]); } }; res.clear(), dfs(dfs, 1); if (f[1] >= 0) res.push_back(1); return res.size() <= K; }; ll l = 0, r = 1e15, ans; while (l <= r) { ll mid = (l + r) / 2; chk(mid) ? r = (ans = mid) - 1 : l = mid + 1; } printf("%lld\n", ans), chk(ans); set<int> S(res.begin(), res.end()); for (int i = 1; i <= n; i++) { if (res.size() < K && !S.count(i)) res.push_back(i); } for (int x : res) printf("%d ", x); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 5008 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 4 ms | 4948 KB | Output is correct |
5 | Correct | 4 ms | 4948 KB | Output is correct |
6 | Correct | 3 ms | 4948 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 3 ms | 4948 KB | Output is correct |
9 | Correct | 4 ms | 5004 KB | Output is correct |
10 | Correct | 3 ms | 5004 KB | Output is correct |
11 | Correct | 3 ms | 4948 KB | Output is correct |
12 | Correct | 3 ms | 5008 KB | Output is correct |
13 | Correct | 3 ms | 5012 KB | Output is correct |
14 | Correct | 3 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 361 ms | 31440 KB | Output is correct |
2 | Correct | 414 ms | 32076 KB | Output is correct |
3 | Correct | 414 ms | 15908 KB | Output is correct |
4 | Correct | 1323 ms | 14964 KB | Output is correct |
5 | Correct | 1235 ms | 18640 KB | Output is correct |
6 | Correct | 1247 ms | 18612 KB | Output is correct |
7 | Correct | 1189 ms | 17440 KB | Output is correct |
8 | Correct | 1321 ms | 18240 KB | Output is correct |
9 | Correct | 1328 ms | 18468 KB | Output is correct |
10 | Correct | 1352 ms | 18788 KB | Output is correct |
11 | Correct | 916 ms | 20552 KB | Output is correct |
12 | Correct | 868 ms | 20584 KB | Output is correct |
13 | Correct | 961 ms | 22052 KB | Output is correct |
14 | Correct | 881 ms | 19108 KB | Output is correct |
15 | Correct | 827 ms | 18748 KB | Output is correct |
16 | Correct | 830 ms | 19996 KB | Output is correct |
17 | Correct | 806 ms | 19308 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 350 ms | 32648 KB | Output is correct |
2 | Correct | 423 ms | 31884 KB | Output is correct |
3 | Correct | 403 ms | 30520 KB | Output is correct |
4 | Correct | 327 ms | 30444 KB | Output is correct |
5 | Correct | 426 ms | 42040 KB | Output is correct |
6 | Correct | 436 ms | 36868 KB | Output is correct |
7 | Correct | 420 ms | 39080 KB | Output is correct |
8 | Correct | 368 ms | 32916 KB | Output is correct |
9 | Correct | 372 ms | 32672 KB | Output is correct |
10 | Correct | 343 ms | 32204 KB | Output is correct |
11 | Correct | 341 ms | 31128 KB | Output is correct |
12 | Correct | 445 ms | 43496 KB | Output is correct |
13 | Correct | 442 ms | 40868 KB | Output is correct |
14 | Correct | 448 ms | 37408 KB | Output is correct |
15 | Correct | 419 ms | 32104 KB | Output is correct |
16 | Correct | 331 ms | 30988 KB | Output is correct |
17 | Correct | 364 ms | 30888 KB | Output is correct |
18 | Correct | 363 ms | 32312 KB | Output is correct |
19 | Correct | 395 ms | 40636 KB | Output is correct |
20 | Correct | 460 ms | 39524 KB | Output is correct |
21 | Correct | 375 ms | 37172 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 3 ms | 5008 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 4 ms | 4948 KB | Output is correct |
5 | Correct | 4 ms | 4948 KB | Output is correct |
6 | Correct | 3 ms | 4948 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 3 ms | 4948 KB | Output is correct |
9 | Correct | 4 ms | 5004 KB | Output is correct |
10 | Correct | 3 ms | 5004 KB | Output is correct |
11 | Correct | 3 ms | 4948 KB | Output is correct |
12 | Correct | 3 ms | 5008 KB | Output is correct |
13 | Correct | 3 ms | 5012 KB | Output is correct |
14 | Correct | 3 ms | 4948 KB | Output is correct |
15 | Correct | 361 ms | 31440 KB | Output is correct |
16 | Correct | 414 ms | 32076 KB | Output is correct |
17 | Correct | 414 ms | 15908 KB | Output is correct |
18 | Correct | 1323 ms | 14964 KB | Output is correct |
19 | Correct | 1235 ms | 18640 KB | Output is correct |
20 | Correct | 1247 ms | 18612 KB | Output is correct |
21 | Correct | 1189 ms | 17440 KB | Output is correct |
22 | Correct | 1321 ms | 18240 KB | Output is correct |
23 | Correct | 1328 ms | 18468 KB | Output is correct |
24 | Correct | 1352 ms | 18788 KB | Output is correct |
25 | Correct | 916 ms | 20552 KB | Output is correct |
26 | Correct | 868 ms | 20584 KB | Output is correct |
27 | Correct | 961 ms | 22052 KB | Output is correct |
28 | Correct | 881 ms | 19108 KB | Output is correct |
29 | Correct | 827 ms | 18748 KB | Output is correct |
30 | Correct | 830 ms | 19996 KB | Output is correct |
31 | Correct | 806 ms | 19308 KB | Output is correct |
32 | Correct | 350 ms | 32648 KB | Output is correct |
33 | Correct | 423 ms | 31884 KB | Output is correct |
34 | Correct | 403 ms | 30520 KB | Output is correct |
35 | Correct | 327 ms | 30444 KB | Output is correct |
36 | Correct | 426 ms | 42040 KB | Output is correct |
37 | Correct | 436 ms | 36868 KB | Output is correct |
38 | Correct | 420 ms | 39080 KB | Output is correct |
39 | Correct | 368 ms | 32916 KB | Output is correct |
40 | Correct | 372 ms | 32672 KB | Output is correct |
41 | Correct | 343 ms | 32204 KB | Output is correct |
42 | Correct | 341 ms | 31128 KB | Output is correct |
43 | Correct | 445 ms | 43496 KB | Output is correct |
44 | Correct | 442 ms | 40868 KB | Output is correct |
45 | Correct | 448 ms | 37408 KB | Output is correct |
46 | Correct | 419 ms | 32104 KB | Output is correct |
47 | Correct | 331 ms | 30988 KB | Output is correct |
48 | Correct | 364 ms | 30888 KB | Output is correct |
49 | Correct | 363 ms | 32312 KB | Output is correct |
50 | Correct | 395 ms | 40636 KB | Output is correct |
51 | Correct | 460 ms | 39524 KB | Output is correct |
52 | Correct | 375 ms | 37172 KB | Output is correct |
53 | Correct | 1190 ms | 18952 KB | Output is correct |
54 | Correct | 1278 ms | 19368 KB | Output is correct |
55 | Correct | 1415 ms | 20044 KB | Output is correct |
56 | Correct | 1444 ms | 20228 KB | Output is correct |
57 | Correct | 1467 ms | 23928 KB | Output is correct |
58 | Correct | 1307 ms | 19084 KB | Output is correct |
59 | Correct | 1429 ms | 30752 KB | Output is correct |
60 | Correct | 1342 ms | 18536 KB | Output is correct |
61 | Correct | 1255 ms | 17312 KB | Output is correct |
62 | Correct | 1244 ms | 22736 KB | Output is correct |
63 | Correct | 1384 ms | 18588 KB | Output is correct |
64 | Correct | 1311 ms | 27940 KB | Output is correct |
65 | Correct | 1285 ms | 19028 KB | Output is correct |
66 | Correct | 1217 ms | 23636 KB | Output is correct |
67 | Correct | 1126 ms | 18096 KB | Output is correct |
68 | Correct | 1405 ms | 30268 KB | Output is correct |
69 | Correct | 350 ms | 36452 KB | Output is correct |
70 | Correct | 335 ms | 33996 KB | Output is correct |
71 | Correct | 406 ms | 41732 KB | Output is correct |
72 | Correct | 368 ms | 19512 KB | Output is correct |
73 | Correct | 361 ms | 19528 KB | Output is correct |
74 | Correct | 379 ms | 24576 KB | Output is correct |
75 | Correct | 803 ms | 21004 KB | Output is correct |
76 | Correct | 872 ms | 20316 KB | Output is correct |
77 | Correct | 822 ms | 20304 KB | Output is correct |
78 | Correct | 820 ms | 21560 KB | Output is correct |