# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
534875 |
2022-03-09T05:28:50 Z |
kartel |
Parkovi (COCI22_parkovi) |
C++14 |
|
1876 ms |
44192 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 << " ";
}
}
Compilation message
Main.cpp: In function 'void dfs(int, int, ll)':
Main.cpp:43:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
43 | for (auto [u, w] : g[v]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 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 |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
2 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
437 ms |
40004 KB |
Output is correct |
2 |
Correct |
500 ms |
42332 KB |
Output is correct |
3 |
Correct |
462 ms |
29760 KB |
Output is correct |
4 |
Correct |
1636 ms |
27804 KB |
Output is correct |
5 |
Correct |
1512 ms |
27088 KB |
Output is correct |
6 |
Correct |
1491 ms |
27112 KB |
Output is correct |
7 |
Correct |
1526 ms |
26032 KB |
Output is correct |
8 |
Correct |
1650 ms |
27100 KB |
Output is correct |
9 |
Correct |
1503 ms |
27308 KB |
Output is correct |
10 |
Correct |
1606 ms |
27900 KB |
Output is correct |
11 |
Correct |
1043 ms |
29068 KB |
Output is correct |
12 |
Correct |
1028 ms |
28648 KB |
Output is correct |
13 |
Correct |
1102 ms |
30876 KB |
Output is correct |
14 |
Correct |
1028 ms |
27260 KB |
Output is correct |
15 |
Correct |
954 ms |
26836 KB |
Output is correct |
16 |
Correct |
1006 ms |
28464 KB |
Output is correct |
17 |
Correct |
986 ms |
27476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
43140 KB |
Output is correct |
2 |
Correct |
466 ms |
42072 KB |
Output is correct |
3 |
Correct |
438 ms |
40112 KB |
Output is correct |
4 |
Correct |
438 ms |
40108 KB |
Output is correct |
5 |
Correct |
515 ms |
43272 KB |
Output is correct |
6 |
Correct |
532 ms |
42832 KB |
Output is correct |
7 |
Correct |
517 ms |
44192 KB |
Output is correct |
8 |
Correct |
441 ms |
42764 KB |
Output is correct |
9 |
Correct |
485 ms |
42280 KB |
Output is correct |
10 |
Correct |
472 ms |
41540 KB |
Output is correct |
11 |
Correct |
448 ms |
40212 KB |
Output is correct |
12 |
Correct |
619 ms |
43968 KB |
Output is correct |
13 |
Correct |
541 ms |
44180 KB |
Output is correct |
14 |
Correct |
506 ms |
43096 KB |
Output is correct |
15 |
Correct |
520 ms |
40848 KB |
Output is correct |
16 |
Correct |
474 ms |
39364 KB |
Output is correct |
17 |
Correct |
466 ms |
38408 KB |
Output is correct |
18 |
Correct |
437 ms |
38328 KB |
Output is correct |
19 |
Correct |
468 ms |
38264 KB |
Output is correct |
20 |
Correct |
458 ms |
39188 KB |
Output is correct |
21 |
Correct |
438 ms |
38304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 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 |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
2 ms |
4940 KB |
Output is correct |
15 |
Correct |
437 ms |
40004 KB |
Output is correct |
16 |
Correct |
500 ms |
42332 KB |
Output is correct |
17 |
Correct |
462 ms |
29760 KB |
Output is correct |
18 |
Correct |
1636 ms |
27804 KB |
Output is correct |
19 |
Correct |
1512 ms |
27088 KB |
Output is correct |
20 |
Correct |
1491 ms |
27112 KB |
Output is correct |
21 |
Correct |
1526 ms |
26032 KB |
Output is correct |
22 |
Correct |
1650 ms |
27100 KB |
Output is correct |
23 |
Correct |
1503 ms |
27308 KB |
Output is correct |
24 |
Correct |
1606 ms |
27900 KB |
Output is correct |
25 |
Correct |
1043 ms |
29068 KB |
Output is correct |
26 |
Correct |
1028 ms |
28648 KB |
Output is correct |
27 |
Correct |
1102 ms |
30876 KB |
Output is correct |
28 |
Correct |
1028 ms |
27260 KB |
Output is correct |
29 |
Correct |
954 ms |
26836 KB |
Output is correct |
30 |
Correct |
1006 ms |
28464 KB |
Output is correct |
31 |
Correct |
986 ms |
27476 KB |
Output is correct |
32 |
Correct |
445 ms |
43140 KB |
Output is correct |
33 |
Correct |
466 ms |
42072 KB |
Output is correct |
34 |
Correct |
438 ms |
40112 KB |
Output is correct |
35 |
Correct |
438 ms |
40108 KB |
Output is correct |
36 |
Correct |
515 ms |
43272 KB |
Output is correct |
37 |
Correct |
532 ms |
42832 KB |
Output is correct |
38 |
Correct |
517 ms |
44192 KB |
Output is correct |
39 |
Correct |
441 ms |
42764 KB |
Output is correct |
40 |
Correct |
485 ms |
42280 KB |
Output is correct |
41 |
Correct |
472 ms |
41540 KB |
Output is correct |
42 |
Correct |
448 ms |
40212 KB |
Output is correct |
43 |
Correct |
619 ms |
43968 KB |
Output is correct |
44 |
Correct |
541 ms |
44180 KB |
Output is correct |
45 |
Correct |
506 ms |
43096 KB |
Output is correct |
46 |
Correct |
520 ms |
40848 KB |
Output is correct |
47 |
Correct |
474 ms |
39364 KB |
Output is correct |
48 |
Correct |
466 ms |
38408 KB |
Output is correct |
49 |
Correct |
437 ms |
38328 KB |
Output is correct |
50 |
Correct |
468 ms |
38264 KB |
Output is correct |
51 |
Correct |
458 ms |
39188 KB |
Output is correct |
52 |
Correct |
438 ms |
38304 KB |
Output is correct |
53 |
Correct |
1555 ms |
23840 KB |
Output is correct |
54 |
Correct |
1663 ms |
24424 KB |
Output is correct |
55 |
Correct |
1763 ms |
25364 KB |
Output is correct |
56 |
Correct |
1650 ms |
24792 KB |
Output is correct |
57 |
Correct |
1581 ms |
25468 KB |
Output is correct |
58 |
Correct |
1593 ms |
23972 KB |
Output is correct |
59 |
Correct |
1876 ms |
26780 KB |
Output is correct |
60 |
Correct |
1660 ms |
24988 KB |
Output is correct |
61 |
Correct |
1403 ms |
23240 KB |
Output is correct |
62 |
Correct |
1478 ms |
24352 KB |
Output is correct |
63 |
Correct |
1665 ms |
25148 KB |
Output is correct |
64 |
Correct |
1606 ms |
25792 KB |
Output is correct |
65 |
Correct |
1657 ms |
24784 KB |
Output is correct |
66 |
Correct |
1609 ms |
24908 KB |
Output is correct |
67 |
Correct |
1473 ms |
26560 KB |
Output is correct |
68 |
Correct |
1666 ms |
30232 KB |
Output is correct |
69 |
Correct |
430 ms |
42448 KB |
Output is correct |
70 |
Correct |
425 ms |
39436 KB |
Output is correct |
71 |
Correct |
518 ms |
43732 KB |
Output is correct |
72 |
Correct |
458 ms |
28336 KB |
Output is correct |
73 |
Correct |
481 ms |
28256 KB |
Output is correct |
74 |
Correct |
471 ms |
29300 KB |
Output is correct |
75 |
Correct |
1006 ms |
29432 KB |
Output is correct |
76 |
Correct |
1052 ms |
29212 KB |
Output is correct |
77 |
Correct |
1014 ms |
28732 KB |
Output is correct |
78 |
Correct |
992 ms |
28612 KB |
Output is correct |