# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
536849 |
2022-03-14T05:59:53 Z |
phathnv |
Parkovi (COCI22_parkovi) |
C++11 |
|
3000 ms |
33356 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, k;
long long dist[N], maxRem[N];
array<int, 2> par[N];
vector<array<int, 2>> adj[N];
vector<int> ord;
bool mark[N], choose[N];
void Dfs1(int u, int p) {
for (auto [v, c] : adj[u]) {
if (v == p) {
continue;
}
dist[v] = dist[u] + c;
par[v] = {u, c};
Dfs1(v, u);
}
}
void Dfs2(int u, int p, long long rem) {
if (rem <= maxRem[u]) {
return;
}
maxRem[u] = rem;
mark[u] = true;
for (auto [v, c] : adj[u]) {
if (v == p) {
continue;
}
Dfs2(v, u, rem - c);
}
}
int calc(long long r) {
fill(mark + 1, mark + 1 + n, false);
fill(choose + 1, choose + 1 + n, false);
fill(maxRem + 1, maxRem + 1 + n, -1);
int res = 0;
for (auto u : ord) {
if (mark[u]) {
continue;
}
long long rem = r;
while (par[u][0] && rem >= par[u][1]) {
rem -= par[u][1];
u = par[u][0];
}
++res;
choose[u] = true;
Dfs2(u, -1, r);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i < n; ++i) {
int u, v, c;
cin >> u >> v >> c;
adj[u].push_back({v, c});
adj[v].push_back({u, c});
}
Dfs1(1, -1);
ord.resize(n);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int u, int v){
return dist[u] > dist[v];
});
long long l = 0, r = 1e15, ans = -1;
while (l <= r) {
long long mid = (l + r) >> 1;
int cnt = calc(mid);
if (cnt <= k) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << ans << '\n';
int cnt = calc(ans);
for (int i = 1; i <= n; ++i) {
if (!choose[i] && cnt < k) {
++cnt;
choose[i] = true;
}
}
for (int i = 1; i <= n; ++i) {
if (choose[i]) {
cout << i << ' ';
}
}
cout << '\n';
return 0;
}
Compilation message
Main.cpp: In function 'void Dfs1(int, int)':
Main.cpp:14:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
14 | for (auto [v, c] : adj[u]) {
| ^
Main.cpp: In function 'void Dfs2(int, int, long long int)':
Main.cpp:30:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | for (auto [v, c] : adj[u]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 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 |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
31032 KB |
Output is correct |
2 |
Correct |
283 ms |
31692 KB |
Output is correct |
3 |
Correct |
353 ms |
18636 KB |
Output is correct |
4 |
Correct |
1671 ms |
17488 KB |
Output is correct |
5 |
Correct |
1559 ms |
17080 KB |
Output is correct |
6 |
Correct |
1145 ms |
17080 KB |
Output is correct |
7 |
Correct |
1326 ms |
17168 KB |
Output is correct |
8 |
Correct |
1348 ms |
17880 KB |
Output is correct |
9 |
Correct |
1763 ms |
17524 KB |
Output is correct |
10 |
Correct |
1503 ms |
17768 KB |
Output is correct |
11 |
Correct |
985 ms |
18656 KB |
Output is correct |
12 |
Correct |
931 ms |
18636 KB |
Output is correct |
13 |
Correct |
1000 ms |
19952 KB |
Output is correct |
14 |
Correct |
843 ms |
18532 KB |
Output is correct |
15 |
Correct |
799 ms |
18172 KB |
Output is correct |
16 |
Correct |
900 ms |
18748 KB |
Output is correct |
17 |
Correct |
941 ms |
18124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
32264 KB |
Output is correct |
2 |
Correct |
201 ms |
31472 KB |
Output is correct |
3 |
Correct |
212 ms |
30132 KB |
Output is correct |
4 |
Correct |
248 ms |
30016 KB |
Output is correct |
5 |
Correct |
208 ms |
32108 KB |
Output is correct |
6 |
Correct |
224 ms |
31852 KB |
Output is correct |
7 |
Correct |
232 ms |
32808 KB |
Output is correct |
8 |
Correct |
212 ms |
32440 KB |
Output is correct |
9 |
Correct |
194 ms |
32124 KB |
Output is correct |
10 |
Correct |
235 ms |
31568 KB |
Output is correct |
11 |
Correct |
243 ms |
30564 KB |
Output is correct |
12 |
Correct |
237 ms |
33116 KB |
Output is correct |
13 |
Correct |
225 ms |
33356 KB |
Output is correct |
14 |
Correct |
261 ms |
32592 KB |
Output is correct |
15 |
Correct |
246 ms |
31624 KB |
Output is correct |
16 |
Correct |
254 ms |
30448 KB |
Output is correct |
17 |
Correct |
248 ms |
30372 KB |
Output is correct |
18 |
Correct |
307 ms |
31772 KB |
Output is correct |
19 |
Correct |
253 ms |
31420 KB |
Output is correct |
20 |
Correct |
265 ms |
32064 KB |
Output is correct |
21 |
Correct |
271 ms |
31436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 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 |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
275 ms |
31032 KB |
Output is correct |
16 |
Correct |
283 ms |
31692 KB |
Output is correct |
17 |
Correct |
353 ms |
18636 KB |
Output is correct |
18 |
Correct |
1671 ms |
17488 KB |
Output is correct |
19 |
Correct |
1559 ms |
17080 KB |
Output is correct |
20 |
Correct |
1145 ms |
17080 KB |
Output is correct |
21 |
Correct |
1326 ms |
17168 KB |
Output is correct |
22 |
Correct |
1348 ms |
17880 KB |
Output is correct |
23 |
Correct |
1763 ms |
17524 KB |
Output is correct |
24 |
Correct |
1503 ms |
17768 KB |
Output is correct |
25 |
Correct |
985 ms |
18656 KB |
Output is correct |
26 |
Correct |
931 ms |
18636 KB |
Output is correct |
27 |
Correct |
1000 ms |
19952 KB |
Output is correct |
28 |
Correct |
843 ms |
18532 KB |
Output is correct |
29 |
Correct |
799 ms |
18172 KB |
Output is correct |
30 |
Correct |
900 ms |
18748 KB |
Output is correct |
31 |
Correct |
941 ms |
18124 KB |
Output is correct |
32 |
Correct |
210 ms |
32264 KB |
Output is correct |
33 |
Correct |
201 ms |
31472 KB |
Output is correct |
34 |
Correct |
212 ms |
30132 KB |
Output is correct |
35 |
Correct |
248 ms |
30016 KB |
Output is correct |
36 |
Correct |
208 ms |
32108 KB |
Output is correct |
37 |
Correct |
224 ms |
31852 KB |
Output is correct |
38 |
Correct |
232 ms |
32808 KB |
Output is correct |
39 |
Correct |
212 ms |
32440 KB |
Output is correct |
40 |
Correct |
194 ms |
32124 KB |
Output is correct |
41 |
Correct |
235 ms |
31568 KB |
Output is correct |
42 |
Correct |
243 ms |
30564 KB |
Output is correct |
43 |
Correct |
237 ms |
33116 KB |
Output is correct |
44 |
Correct |
225 ms |
33356 KB |
Output is correct |
45 |
Correct |
261 ms |
32592 KB |
Output is correct |
46 |
Correct |
246 ms |
31624 KB |
Output is correct |
47 |
Correct |
254 ms |
30448 KB |
Output is correct |
48 |
Correct |
248 ms |
30372 KB |
Output is correct |
49 |
Correct |
307 ms |
31772 KB |
Output is correct |
50 |
Correct |
253 ms |
31420 KB |
Output is correct |
51 |
Correct |
265 ms |
32064 KB |
Output is correct |
52 |
Correct |
271 ms |
31436 KB |
Output is correct |
53 |
Execution timed out |
3083 ms |
17400 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |