# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059461 | 2024-08-15T01:44:05 Z | Flan312 | Parkovi (COCI22_parkovi) | C++17 | 321 ms | 35368 KB |
#include <bits/stdc++.h> #define ll long long #define ld long double #define eb emplace_back #define task "CONGVIEN" #define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout); #define fi first #define se second #define pii pair <int, int> #define tii tuple <int, int, int> #define all(s) s.begin(), s.end() using namespace std; const ll oo = 1e18; const int nmax = 2e5 + 2; int n, k; bool placed_park[nmax]; vector <pii> adj[nmax]; ll r = 0; int cnt = 0; ll dist[nmax], reach[nmax]; void dfs(int u, int par, ll mxDist) { dist[u] = oo; reach[u] = 0; for (auto &[v, w] : adj[u]) { if (v == par) continue; dfs(v, u, mxDist); if (reach[v] + min(1ll * w, dist[v]) <= mxDist) { placed_park[v] = 0; if (reach[v] + dist[v] > mxDist) reach[u] = max(reach[u], reach[v] + w); dist[u] = min(dist[u], dist[v] + w); } else { placed_park[v] = 1; ++cnt; dist[u] = min(dist[u], 1ll * w); } } } bool check(ll mxDist) { cnt = 0; dfs(1, -1, mxDist); if (reach[1] + dist[1] <= mxDist) placed_park[1] = 0; else { placed_park[1] = 1; ++cnt; } return cnt <= k; } int main() { if (ifstream(task".inp")) nx fast cin >> n >> k; for (int u, v, w, i = 1; i < n; ++i) { cin >> u >> v >> w; adj[u].eb(v, w); adj[v].eb(u, w); r += w; } ll l = 0, ans = -1; while(l <= r) { ll mid = l + r >> 1; if (check(mid)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans << '\n'; check(ans); vector <int> res; for (int i = 1; i <= n; ++i) if (placed_park[i]) res.eb(i); for (int i = 1; i <= n; ++i) if (res.size() < k && !placed_park[i]) res.eb(i); for (auto &i : res) cout << i << ' '; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8108 KB | Output is correct |
2 | Correct | 1 ms | 8028 KB | Output is correct |
3 | Correct | 1 ms | 8028 KB | Output is correct |
4 | Correct | 1 ms | 8028 KB | Output is correct |
5 | Correct | 1 ms | 8028 KB | Output is correct |
6 | Correct | 1 ms | 8028 KB | Output is correct |
7 | Correct | 1 ms | 8028 KB | Output is correct |
8 | Correct | 1 ms | 8028 KB | Output is correct |
9 | Correct | 1 ms | 8028 KB | Output is correct |
10 | Correct | 1 ms | 8108 KB | Output is correct |
11 | Correct | 1 ms | 8028 KB | Output is correct |
12 | Correct | 1 ms | 8028 KB | Output is correct |
13 | Correct | 1 ms | 8028 KB | Output is correct |
14 | Correct | 1 ms | 8024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 31812 KB | Output is correct |
2 | Correct | 153 ms | 33620 KB | Output is correct |
3 | Correct | 126 ms | 20676 KB | Output is correct |
4 | Correct | 276 ms | 19540 KB | Output is correct |
5 | Correct | 263 ms | 19028 KB | Output is correct |
6 | Correct | 284 ms | 19028 KB | Output is correct |
7 | Correct | 144 ms | 18004 KB | Output is correct |
8 | Correct | 150 ms | 18408 KB | Output is correct |
9 | Correct | 269 ms | 18772 KB | Output is correct |
10 | Correct | 286 ms | 19028 KB | Output is correct |
11 | Correct | 247 ms | 20568 KB | Output is correct |
12 | Correct | 243 ms | 20820 KB | Output is correct |
13 | Correct | 270 ms | 21844 KB | Output is correct |
14 | Correct | 129 ms | 19392 KB | Output is correct |
15 | Correct | 131 ms | 18772 KB | Output is correct |
16 | Correct | 234 ms | 20340 KB | Output is correct |
17 | Correct | 227 ms | 19464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 160 ms | 34228 KB | Output is correct |
2 | Correct | 145 ms | 33364 KB | Output is correct |
3 | Correct | 136 ms | 32084 KB | Output is correct |
4 | Correct | 128 ms | 32080 KB | Output is correct |
5 | Correct | 169 ms | 34936 KB | Output is correct |
6 | Correct | 185 ms | 34256 KB | Output is correct |
7 | Correct | 185 ms | 35368 KB | Output is correct |
8 | Correct | 153 ms | 33796 KB | Output is correct |
9 | Correct | 150 ms | 33364 KB | Output is correct |
10 | Correct | 145 ms | 32964 KB | Output is correct |
11 | Correct | 130 ms | 32140 KB | Output is correct |
12 | Correct | 172 ms | 35280 KB | Output is correct |
13 | Correct | 185 ms | 35272 KB | Output is correct |
14 | Correct | 195 ms | 34488 KB | Output is correct |
15 | Correct | 84 ms | 32084 KB | Output is correct |
16 | Correct | 80 ms | 31312 KB | Output is correct |
17 | Correct | 86 ms | 31060 KB | Output is correct |
18 | Correct | 90 ms | 32512 KB | Output is correct |
19 | Correct | 102 ms | 33008 KB | Output is correct |
20 | Correct | 105 ms | 33372 KB | Output is correct |
21 | Correct | 101 ms | 32720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8108 KB | Output is correct |
2 | Correct | 1 ms | 8028 KB | Output is correct |
3 | Correct | 1 ms | 8028 KB | Output is correct |
4 | Correct | 1 ms | 8028 KB | Output is correct |
5 | Correct | 1 ms | 8028 KB | Output is correct |
6 | Correct | 1 ms | 8028 KB | Output is correct |
7 | Correct | 1 ms | 8028 KB | Output is correct |
8 | Correct | 1 ms | 8028 KB | Output is correct |
9 | Correct | 1 ms | 8028 KB | Output is correct |
10 | Correct | 1 ms | 8108 KB | Output is correct |
11 | Correct | 1 ms | 8028 KB | Output is correct |
12 | Correct | 1 ms | 8028 KB | Output is correct |
13 | Correct | 1 ms | 8028 KB | Output is correct |
14 | Correct | 1 ms | 8024 KB | Output is correct |
15 | Correct | 93 ms | 31812 KB | Output is correct |
16 | Correct | 153 ms | 33620 KB | Output is correct |
17 | Correct | 126 ms | 20676 KB | Output is correct |
18 | Correct | 276 ms | 19540 KB | Output is correct |
19 | Correct | 263 ms | 19028 KB | Output is correct |
20 | Correct | 284 ms | 19028 KB | Output is correct |
21 | Correct | 144 ms | 18004 KB | Output is correct |
22 | Correct | 150 ms | 18408 KB | Output is correct |
23 | Correct | 269 ms | 18772 KB | Output is correct |
24 | Correct | 286 ms | 19028 KB | Output is correct |
25 | Correct | 247 ms | 20568 KB | Output is correct |
26 | Correct | 243 ms | 20820 KB | Output is correct |
27 | Correct | 270 ms | 21844 KB | Output is correct |
28 | Correct | 129 ms | 19392 KB | Output is correct |
29 | Correct | 131 ms | 18772 KB | Output is correct |
30 | Correct | 234 ms | 20340 KB | Output is correct |
31 | Correct | 227 ms | 19464 KB | Output is correct |
32 | Correct | 160 ms | 34228 KB | Output is correct |
33 | Correct | 145 ms | 33364 KB | Output is correct |
34 | Correct | 136 ms | 32084 KB | Output is correct |
35 | Correct | 128 ms | 32080 KB | Output is correct |
36 | Correct | 169 ms | 34936 KB | Output is correct |
37 | Correct | 185 ms | 34256 KB | Output is correct |
38 | Correct | 185 ms | 35368 KB | Output is correct |
39 | Correct | 153 ms | 33796 KB | Output is correct |
40 | Correct | 150 ms | 33364 KB | Output is correct |
41 | Correct | 145 ms | 32964 KB | Output is correct |
42 | Correct | 130 ms | 32140 KB | Output is correct |
43 | Correct | 172 ms | 35280 KB | Output is correct |
44 | Correct | 185 ms | 35272 KB | Output is correct |
45 | Correct | 195 ms | 34488 KB | Output is correct |
46 | Correct | 84 ms | 32084 KB | Output is correct |
47 | Correct | 80 ms | 31312 KB | Output is correct |
48 | Correct | 86 ms | 31060 KB | Output is correct |
49 | Correct | 90 ms | 32512 KB | Output is correct |
50 | Correct | 102 ms | 33008 KB | Output is correct |
51 | Correct | 105 ms | 33372 KB | Output is correct |
52 | Correct | 101 ms | 32720 KB | Output is correct |
53 | Correct | 285 ms | 19524 KB | Output is correct |
54 | Correct | 289 ms | 19728 KB | Output is correct |
55 | Correct | 296 ms | 20512 KB | Output is correct |
56 | Correct | 295 ms | 20132 KB | Output is correct |
57 | Correct | 304 ms | 20680 KB | Output is correct |
58 | Correct | 269 ms | 19540 KB | Output is correct |
59 | Correct | 293 ms | 22184 KB | Output is correct |
60 | Correct | 160 ms | 18772 KB | Output is correct |
61 | Correct | 152 ms | 17736 KB | Output is correct |
62 | Correct | 145 ms | 18892 KB | Output is correct |
63 | Correct | 161 ms | 18808 KB | Output is correct |
64 | Correct | 159 ms | 20248 KB | Output is correct |
65 | Correct | 287 ms | 19284 KB | Output is correct |
66 | Correct | 290 ms | 19916 KB | Output is correct |
67 | Correct | 268 ms | 18588 KB | Output is correct |
68 | Correct | 321 ms | 21448 KB | Output is correct |
69 | Correct | 145 ms | 33620 KB | Output is correct |
70 | Correct | 129 ms | 31840 KB | Output is correct |
71 | Correct | 203 ms | 34768 KB | Output is correct |
72 | Correct | 108 ms | 19912 KB | Output is correct |
73 | Correct | 68 ms | 19152 KB | Output is correct |
74 | Correct | 77 ms | 20764 KB | Output is correct |
75 | Correct | 243 ms | 21076 KB | Output is correct |
76 | Correct | 148 ms | 20304 KB | Output is correct |
77 | Correct | 246 ms | 20472 KB | Output is correct |
78 | Correct | 142 ms | 20180 KB | Output is correct |