# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
526764 |
2022-02-16T04:32:22 Z |
hmm789 |
Parkovi (COCI22_parkovi) |
C++14 |
|
1219 ms |
32184 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int, int>> adj[200000];
vector<int> vec;
pair<int, int> dp(int x, int v, int par) {
int mxover = -1e18, mxunder = 0, pard;
for(auto i : adj[x]) {
if(i.first == par) {
pard = i.second;
continue;
}
pair<int, int> tmp = dp(i.first, v, x);
if(tmp.first == -1) mxunder = max(mxunder, tmp.second);
else mxover = max(mxover, tmp.second);
}
if(par == -1) pard = 2e18;
pair<int, int> res;
if(mxover >= mxunder) {
res = make_pair(1, mxover-pard);
} else {
res = make_pair(-1, mxunder + pard);
}
if(res.first == -1 && res.second > v) {
vec.push_back(x);
res = make_pair(1, v-pard);
}
if(res.first == 1 && res.second < 0) {
res = make_pair(-1, 0);
}
return res;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k, x, y, w;
cin >> n >> k;
for(int i = 0; i < n-1; i++) {
cin >> x >> y >> w;
x--; y--;
adj[x].push_back(make_pair(y, w));
adj[y].push_back(make_pair(x, w));
}
int l = 0, r = 1e18, m;
while(l < r) {
m = (l+r)/2;
vec.clear();
dp(0, m, -1);
if(vec.size() > k) l = m+1;
else r = m;
}
vec.clear();
dp(0, l, -1);
cout << l << '\n';
sort(vec.begin(), vec.end());
for(int i : vec) cout << i+1 << " ";
int idx = 0, cnt = vec.size();
for(int i = 1; i <= n; i++) {
if(cnt == k) break;
if(vec[idx] != i-1) {
cout << i << " ";
cnt++;
}
else idx++;
}
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:53:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
53 | if(vec.size() > k) l = m+1;
| ~~~~~~~~~~~^~~
Main.cpp: In function 'std::pair<long long int, long long int> dp(long long int, long long int, long long int)':
Main.cpp:25:31: warning: 'pard' may be used uninitialized in this function [-Wmaybe-uninitialized]
25 | res = make_pair(-1, mxunder + pard);
| ~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4988 KB |
Output is correct |
4 |
Correct |
2 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5004 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
5012 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
351 ms |
28836 KB |
Output is correct |
2 |
Correct |
338 ms |
29324 KB |
Output is correct |
3 |
Correct |
244 ms |
14724 KB |
Output is correct |
4 |
Correct |
1046 ms |
14900 KB |
Output is correct |
5 |
Correct |
999 ms |
14664 KB |
Output is correct |
6 |
Correct |
980 ms |
14588 KB |
Output is correct |
7 |
Correct |
993 ms |
14640 KB |
Output is correct |
8 |
Correct |
1055 ms |
15012 KB |
Output is correct |
9 |
Correct |
1006 ms |
14688 KB |
Output is correct |
10 |
Correct |
1074 ms |
15112 KB |
Output is correct |
11 |
Correct |
688 ms |
16080 KB |
Output is correct |
12 |
Correct |
658 ms |
16248 KB |
Output is correct |
13 |
Correct |
733 ms |
17220 KB |
Output is correct |
14 |
Correct |
649 ms |
16044 KB |
Output is correct |
15 |
Correct |
655 ms |
15724 KB |
Output is correct |
16 |
Correct |
656 ms |
16496 KB |
Output is correct |
17 |
Correct |
653 ms |
15676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
29832 KB |
Output is correct |
2 |
Correct |
338 ms |
29124 KB |
Output is correct |
3 |
Correct |
315 ms |
27972 KB |
Output is correct |
4 |
Correct |
310 ms |
27840 KB |
Output is correct |
5 |
Correct |
376 ms |
31440 KB |
Output is correct |
6 |
Correct |
389 ms |
30492 KB |
Output is correct |
7 |
Correct |
381 ms |
31868 KB |
Output is correct |
8 |
Correct |
342 ms |
29828 KB |
Output is correct |
9 |
Correct |
358 ms |
29764 KB |
Output is correct |
10 |
Correct |
334 ms |
29112 KB |
Output is correct |
11 |
Correct |
316 ms |
28096 KB |
Output is correct |
12 |
Correct |
381 ms |
32184 KB |
Output is correct |
13 |
Correct |
389 ms |
31800 KB |
Output is correct |
14 |
Correct |
398 ms |
30680 KB |
Output is correct |
15 |
Correct |
335 ms |
29068 KB |
Output is correct |
16 |
Correct |
309 ms |
28100 KB |
Output is correct |
17 |
Correct |
320 ms |
27888 KB |
Output is correct |
18 |
Correct |
330 ms |
29160 KB |
Output is correct |
19 |
Correct |
342 ms |
30428 KB |
Output is correct |
20 |
Correct |
351 ms |
30840 KB |
Output is correct |
21 |
Correct |
341 ms |
30400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4988 KB |
Output is correct |
4 |
Correct |
2 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5004 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
5012 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
351 ms |
28836 KB |
Output is correct |
16 |
Correct |
338 ms |
29324 KB |
Output is correct |
17 |
Correct |
244 ms |
14724 KB |
Output is correct |
18 |
Correct |
1046 ms |
14900 KB |
Output is correct |
19 |
Correct |
999 ms |
14664 KB |
Output is correct |
20 |
Correct |
980 ms |
14588 KB |
Output is correct |
21 |
Correct |
993 ms |
14640 KB |
Output is correct |
22 |
Correct |
1055 ms |
15012 KB |
Output is correct |
23 |
Correct |
1006 ms |
14688 KB |
Output is correct |
24 |
Correct |
1074 ms |
15112 KB |
Output is correct |
25 |
Correct |
688 ms |
16080 KB |
Output is correct |
26 |
Correct |
658 ms |
16248 KB |
Output is correct |
27 |
Correct |
733 ms |
17220 KB |
Output is correct |
28 |
Correct |
649 ms |
16044 KB |
Output is correct |
29 |
Correct |
655 ms |
15724 KB |
Output is correct |
30 |
Correct |
656 ms |
16496 KB |
Output is correct |
31 |
Correct |
653 ms |
15676 KB |
Output is correct |
32 |
Correct |
348 ms |
29832 KB |
Output is correct |
33 |
Correct |
338 ms |
29124 KB |
Output is correct |
34 |
Correct |
315 ms |
27972 KB |
Output is correct |
35 |
Correct |
310 ms |
27840 KB |
Output is correct |
36 |
Correct |
376 ms |
31440 KB |
Output is correct |
37 |
Correct |
389 ms |
30492 KB |
Output is correct |
38 |
Correct |
381 ms |
31868 KB |
Output is correct |
39 |
Correct |
342 ms |
29828 KB |
Output is correct |
40 |
Correct |
358 ms |
29764 KB |
Output is correct |
41 |
Correct |
334 ms |
29112 KB |
Output is correct |
42 |
Correct |
316 ms |
28096 KB |
Output is correct |
43 |
Correct |
381 ms |
32184 KB |
Output is correct |
44 |
Correct |
389 ms |
31800 KB |
Output is correct |
45 |
Correct |
398 ms |
30680 KB |
Output is correct |
46 |
Correct |
335 ms |
29068 KB |
Output is correct |
47 |
Correct |
309 ms |
28100 KB |
Output is correct |
48 |
Correct |
320 ms |
27888 KB |
Output is correct |
49 |
Correct |
330 ms |
29160 KB |
Output is correct |
50 |
Correct |
342 ms |
30428 KB |
Output is correct |
51 |
Correct |
351 ms |
30840 KB |
Output is correct |
52 |
Correct |
341 ms |
30400 KB |
Output is correct |
53 |
Correct |
1045 ms |
14648 KB |
Output is correct |
54 |
Correct |
1053 ms |
14916 KB |
Output is correct |
55 |
Correct |
1118 ms |
15160 KB |
Output is correct |
56 |
Correct |
1101 ms |
15300 KB |
Output is correct |
57 |
Correct |
1086 ms |
16332 KB |
Output is correct |
58 |
Correct |
1014 ms |
14744 KB |
Output is correct |
59 |
Correct |
1168 ms |
17900 KB |
Output is correct |
60 |
Correct |
1132 ms |
15204 KB |
Output is correct |
61 |
Correct |
967 ms |
14276 KB |
Output is correct |
62 |
Correct |
1002 ms |
15932 KB |
Output is correct |
63 |
Correct |
1118 ms |
15156 KB |
Output is correct |
64 |
Correct |
1071 ms |
17328 KB |
Output is correct |
65 |
Correct |
1219 ms |
14960 KB |
Output is correct |
66 |
Correct |
1070 ms |
15956 KB |
Output is correct |
67 |
Correct |
1020 ms |
14404 KB |
Output is correct |
68 |
Correct |
1158 ms |
17972 KB |
Output is correct |
69 |
Correct |
326 ms |
28936 KB |
Output is correct |
70 |
Correct |
311 ms |
27736 KB |
Output is correct |
71 |
Correct |
397 ms |
31116 KB |
Output is correct |
72 |
Correct |
215 ms |
13960 KB |
Output is correct |
73 |
Correct |
219 ms |
15648 KB |
Output is correct |
74 |
Correct |
245 ms |
17924 KB |
Output is correct |
75 |
Correct |
676 ms |
16400 KB |
Output is correct |
76 |
Correct |
737 ms |
16836 KB |
Output is correct |
77 |
Correct |
692 ms |
16324 KB |
Output is correct |
78 |
Correct |
707 ms |
16868 KB |
Output is correct |