# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
534877 |
2022-03-09T05:30:43 Z |
kartel |
Parkovi (COCI22_parkovi) |
C++17 |
|
1659 ms |
40392 KB |
#include <bits/stdc++.h>
//#include<ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC target("avx2")
//#pragma comment(linker, "/STACK:268435456")
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define F first
#define S second
#define pb push_back
#define sz(x) int(x.size())
#define el '\n'
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_pbds;
//using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;
typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 2e5 + 500;
vector <int> ans;
ll dp_down[N], dp_up[N], D;
int n, k;
int u, v, w;
vector <pair <int, int> > g[N];
void dfs(int v, int pr, ll d) {
dp_down[v] = 1e18;
dp_up[v] = 0;
for (auto [u, w] : g[v]) {
if (u == pr) {
continue;
}
dfs(u, v, w);
dp_down[v] = min(dp_down[v], dp_down[u]);
dp_up[v] = max(dp_up[v], dp_up[u]);
}
if (dp_down[v] + dp_up[v] <= D) {
dp_up[v] = -1e18;
}
if (dp_up[v] != -1e18 && (pr == -1 || d + dp_up[v] > D)) {
ans.pb(v);
dp_down[v] = 0;
dp_up[v] = -1e18;
}
dp_down[v] += d; dp_up[v] += d;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("anti.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n - 1; i++) {
cin >> u >> v >> w;
g[v].pb({u, w});
g[u].pb({v, w});
}
ll l = 0;
ll r = (ll)1e18;
while (l < r) {
ll md = (l + r) >> 1;
ans.clear(); D = md;
dfs(1, -1, 0);
if (sz(ans) > k) {
l = md + 1;
} else {
r = md;
}
}
D = l;
ans.clear();
dfs(1, -1, 0);
map <int, int> used;
for (auto x : ans) {
used[x] = 1;
}
for (int i = 1; i <= n; i++) {
if (!used[i] && sz(ans) < k) {
ans.pb(i);
}
}
cout << l << el;
for (auto x : ans) {
cout << x << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
2 ms |
4940 KB |
Output is correct |
7 |
Correct |
2 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
396 ms |
37280 KB |
Output is correct |
2 |
Correct |
454 ms |
38092 KB |
Output is correct |
3 |
Correct |
485 ms |
25240 KB |
Output is correct |
4 |
Correct |
1550 ms |
23644 KB |
Output is correct |
5 |
Correct |
1421 ms |
23192 KB |
Output is correct |
6 |
Correct |
1419 ms |
23108 KB |
Output is correct |
7 |
Correct |
1438 ms |
23388 KB |
Output is correct |
8 |
Correct |
1560 ms |
24188 KB |
Output is correct |
9 |
Correct |
1432 ms |
23672 KB |
Output is correct |
10 |
Correct |
1478 ms |
24288 KB |
Output is correct |
11 |
Correct |
969 ms |
24936 KB |
Output is correct |
12 |
Correct |
925 ms |
24660 KB |
Output is correct |
13 |
Correct |
1028 ms |
26556 KB |
Output is correct |
14 |
Correct |
904 ms |
24672 KB |
Output is correct |
15 |
Correct |
942 ms |
24120 KB |
Output is correct |
16 |
Correct |
1049 ms |
24868 KB |
Output is correct |
17 |
Correct |
963 ms |
24108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
441 ms |
38652 KB |
Output is correct |
2 |
Correct |
472 ms |
37840 KB |
Output is correct |
3 |
Correct |
453 ms |
36108 KB |
Output is correct |
4 |
Correct |
417 ms |
35980 KB |
Output is correct |
5 |
Correct |
481 ms |
39264 KB |
Output is correct |
6 |
Correct |
472 ms |
38592 KB |
Output is correct |
7 |
Correct |
489 ms |
40004 KB |
Output is correct |
8 |
Correct |
417 ms |
38852 KB |
Output is correct |
9 |
Correct |
427 ms |
38596 KB |
Output is correct |
10 |
Correct |
418 ms |
38000 KB |
Output is correct |
11 |
Correct |
397 ms |
36736 KB |
Output is correct |
12 |
Correct |
527 ms |
40392 KB |
Output is correct |
13 |
Correct |
484 ms |
40376 KB |
Output is correct |
14 |
Correct |
472 ms |
39368 KB |
Output is correct |
15 |
Correct |
406 ms |
37952 KB |
Output is correct |
16 |
Correct |
393 ms |
36600 KB |
Output is correct |
17 |
Correct |
381 ms |
36420 KB |
Output is correct |
18 |
Correct |
403 ms |
38224 KB |
Output is correct |
19 |
Correct |
425 ms |
38200 KB |
Output is correct |
20 |
Correct |
431 ms |
39020 KB |
Output is correct |
21 |
Correct |
427 ms |
38256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
2 ms |
4940 KB |
Output is correct |
7 |
Correct |
2 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
396 ms |
37280 KB |
Output is correct |
16 |
Correct |
454 ms |
38092 KB |
Output is correct |
17 |
Correct |
485 ms |
25240 KB |
Output is correct |
18 |
Correct |
1550 ms |
23644 KB |
Output is correct |
19 |
Correct |
1421 ms |
23192 KB |
Output is correct |
20 |
Correct |
1419 ms |
23108 KB |
Output is correct |
21 |
Correct |
1438 ms |
23388 KB |
Output is correct |
22 |
Correct |
1560 ms |
24188 KB |
Output is correct |
23 |
Correct |
1432 ms |
23672 KB |
Output is correct |
24 |
Correct |
1478 ms |
24288 KB |
Output is correct |
25 |
Correct |
969 ms |
24936 KB |
Output is correct |
26 |
Correct |
925 ms |
24660 KB |
Output is correct |
27 |
Correct |
1028 ms |
26556 KB |
Output is correct |
28 |
Correct |
904 ms |
24672 KB |
Output is correct |
29 |
Correct |
942 ms |
24120 KB |
Output is correct |
30 |
Correct |
1049 ms |
24868 KB |
Output is correct |
31 |
Correct |
963 ms |
24108 KB |
Output is correct |
32 |
Correct |
441 ms |
38652 KB |
Output is correct |
33 |
Correct |
472 ms |
37840 KB |
Output is correct |
34 |
Correct |
453 ms |
36108 KB |
Output is correct |
35 |
Correct |
417 ms |
35980 KB |
Output is correct |
36 |
Correct |
481 ms |
39264 KB |
Output is correct |
37 |
Correct |
472 ms |
38592 KB |
Output is correct |
38 |
Correct |
489 ms |
40004 KB |
Output is correct |
39 |
Correct |
417 ms |
38852 KB |
Output is correct |
40 |
Correct |
427 ms |
38596 KB |
Output is correct |
41 |
Correct |
418 ms |
38000 KB |
Output is correct |
42 |
Correct |
397 ms |
36736 KB |
Output is correct |
43 |
Correct |
527 ms |
40392 KB |
Output is correct |
44 |
Correct |
484 ms |
40376 KB |
Output is correct |
45 |
Correct |
472 ms |
39368 KB |
Output is correct |
46 |
Correct |
406 ms |
37952 KB |
Output is correct |
47 |
Correct |
393 ms |
36600 KB |
Output is correct |
48 |
Correct |
381 ms |
36420 KB |
Output is correct |
49 |
Correct |
403 ms |
38224 KB |
Output is correct |
50 |
Correct |
425 ms |
38200 KB |
Output is correct |
51 |
Correct |
431 ms |
39020 KB |
Output is correct |
52 |
Correct |
427 ms |
38256 KB |
Output is correct |
53 |
Correct |
1463 ms |
23564 KB |
Output is correct |
54 |
Correct |
1482 ms |
24112 KB |
Output is correct |
55 |
Correct |
1583 ms |
24924 KB |
Output is correct |
56 |
Correct |
1557 ms |
24448 KB |
Output is correct |
57 |
Correct |
1525 ms |
25328 KB |
Output is correct |
58 |
Correct |
1465 ms |
23876 KB |
Output is correct |
59 |
Correct |
1659 ms |
26400 KB |
Output is correct |
60 |
Correct |
1580 ms |
24772 KB |
Output is correct |
61 |
Correct |
1389 ms |
23120 KB |
Output is correct |
62 |
Correct |
1434 ms |
24188 KB |
Output is correct |
63 |
Correct |
1614 ms |
24984 KB |
Output is correct |
64 |
Correct |
1521 ms |
25664 KB |
Output is correct |
65 |
Correct |
1534 ms |
24376 KB |
Output is correct |
66 |
Correct |
1527 ms |
24632 KB |
Output is correct |
67 |
Correct |
1395 ms |
23128 KB |
Output is correct |
68 |
Correct |
1619 ms |
26572 KB |
Output is correct |
69 |
Correct |
412 ms |
38084 KB |
Output is correct |
70 |
Correct |
393 ms |
36296 KB |
Output is correct |
71 |
Correct |
476 ms |
40164 KB |
Output is correct |
72 |
Correct |
396 ms |
24240 KB |
Output is correct |
73 |
Correct |
411 ms |
25164 KB |
Output is correct |
74 |
Correct |
492 ms |
26184 KB |
Output is correct |
75 |
Correct |
969 ms |
25228 KB |
Output is correct |
76 |
Correct |
1045 ms |
26344 KB |
Output is correct |
77 |
Correct |
976 ms |
25144 KB |
Output is correct |
78 |
Correct |
992 ms |
25700 KB |
Output is correct |