답안 #534934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534934 2022-03-09T07:14:39 Z N1NT3NDO Parkovi (COCI22_parkovi) C++17
110 / 110
1583 ms 31600 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) (int)x.size()
#define fi first
#define sd second
#define all(x) x.begin(), x.end()
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = (int)2e5 + 500;
vector< pair<int, int> > g[N];
ll dp_down[N], dp_up[N], cur;
int n, k;
vector<int> ans;
bool used[N];

void dfs(int v, int pr, ll d)
{
    dp_down[v] = 1e18;
    dp_up[v] = 0;
    for(const 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] <= cur)
      dp_up[v] = -1e18;

    if (dp_up[v] != -1e18 && (pr == -1 || dp_up[v] + d > cur))
    {
        dp_down[v] = 0;
        dp_up[v] = -1e18;
        ans.pb(v);
    }

    dp_down[v] += d; dp_up[v] += d;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i < n; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].pb({v, w});
        g[v].pb({u, w});
    }

    ll l = 0, r = 2e14;

    while(l < r)
    {
        ll m = (l + r) / 2ll;
        cur = m;
        ans.clear();
        dfs(1, -1, 0);

        if (sz(ans) <= k) r = m;
        else l = m + 1;
    }

    cur = l;
    ans.clear();
    dfs(1, -1, 0);

    cout << l << '\n';
    for(auto &u : ans) used[u] = 1;
    for(int i = 1; i <= n; i++)
      if (sz(ans) < k && !used[i])
        {
            ans.pb(i);
        }

    for(auto u : ans) cout << u << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4936 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 2 ms 4940 KB Output is correct
8 Correct 3 ms 5008 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 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 28492 KB Output is correct
2 Correct 368 ms 29140 KB Output is correct
3 Correct 415 ms 16432 KB Output is correct
4 Correct 1448 ms 14948 KB Output is correct
5 Correct 1412 ms 14656 KB Output is correct
6 Correct 1327 ms 14636 KB Output is correct
7 Correct 1362 ms 14720 KB Output is correct
8 Correct 1445 ms 15236 KB Output is correct
9 Correct 1349 ms 14964 KB Output is correct
10 Correct 1392 ms 15208 KB Output is correct
11 Correct 821 ms 16116 KB Output is correct
12 Correct 846 ms 16220 KB Output is correct
13 Correct 900 ms 17324 KB Output is correct
14 Correct 823 ms 16080 KB Output is correct
15 Correct 845 ms 15680 KB Output is correct
16 Correct 806 ms 16432 KB Output is correct
17 Correct 873 ms 15668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 388 ms 29564 KB Output is correct
2 Correct 429 ms 28840 KB Output is correct
3 Correct 399 ms 27660 KB Output is correct
4 Correct 394 ms 27608 KB Output is correct
5 Correct 429 ms 30668 KB Output is correct
6 Correct 483 ms 30120 KB Output is correct
7 Correct 486 ms 31008 KB Output is correct
8 Correct 420 ms 29724 KB Output is correct
9 Correct 390 ms 29492 KB Output is correct
10 Correct 556 ms 29024 KB Output is correct
11 Correct 416 ms 28128 KB Output is correct
12 Correct 486 ms 31600 KB Output is correct
13 Correct 532 ms 31496 KB Output is correct
14 Correct 545 ms 30536 KB Output is correct
15 Correct 365 ms 28996 KB Output is correct
16 Correct 386 ms 28004 KB Output is correct
17 Correct 394 ms 27920 KB Output is correct
18 Correct 473 ms 29088 KB Output is correct
19 Correct 379 ms 29952 KB Output is correct
20 Correct 402 ms 30432 KB Output is correct
21 Correct 389 ms 29836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4936 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 2 ms 4940 KB Output is correct
8 Correct 3 ms 5008 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 3 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 448 ms 28492 KB Output is correct
16 Correct 368 ms 29140 KB Output is correct
17 Correct 415 ms 16432 KB Output is correct
18 Correct 1448 ms 14948 KB Output is correct
19 Correct 1412 ms 14656 KB Output is correct
20 Correct 1327 ms 14636 KB Output is correct
21 Correct 1362 ms 14720 KB Output is correct
22 Correct 1445 ms 15236 KB Output is correct
23 Correct 1349 ms 14964 KB Output is correct
24 Correct 1392 ms 15208 KB Output is correct
25 Correct 821 ms 16116 KB Output is correct
26 Correct 846 ms 16220 KB Output is correct
27 Correct 900 ms 17324 KB Output is correct
28 Correct 823 ms 16080 KB Output is correct
29 Correct 845 ms 15680 KB Output is correct
30 Correct 806 ms 16432 KB Output is correct
31 Correct 873 ms 15668 KB Output is correct
32 Correct 388 ms 29564 KB Output is correct
33 Correct 429 ms 28840 KB Output is correct
34 Correct 399 ms 27660 KB Output is correct
35 Correct 394 ms 27608 KB Output is correct
36 Correct 429 ms 30668 KB Output is correct
37 Correct 483 ms 30120 KB Output is correct
38 Correct 486 ms 31008 KB Output is correct
39 Correct 420 ms 29724 KB Output is correct
40 Correct 390 ms 29492 KB Output is correct
41 Correct 556 ms 29024 KB Output is correct
42 Correct 416 ms 28128 KB Output is correct
43 Correct 486 ms 31600 KB Output is correct
44 Correct 532 ms 31496 KB Output is correct
45 Correct 545 ms 30536 KB Output is correct
46 Correct 365 ms 28996 KB Output is correct
47 Correct 386 ms 28004 KB Output is correct
48 Correct 394 ms 27920 KB Output is correct
49 Correct 473 ms 29088 KB Output is correct
50 Correct 379 ms 29952 KB Output is correct
51 Correct 402 ms 30432 KB Output is correct
52 Correct 389 ms 29836 KB Output is correct
53 Correct 1583 ms 14996 KB Output is correct
54 Correct 1470 ms 15168 KB Output is correct
55 Correct 1571 ms 15684 KB Output is correct
56 Correct 1279 ms 15912 KB Output is correct
57 Correct 1350 ms 16656 KB Output is correct
58 Correct 1315 ms 14944 KB Output is correct
59 Correct 1457 ms 17724 KB Output is correct
60 Correct 1382 ms 15568 KB Output is correct
61 Correct 1160 ms 14648 KB Output is correct
62 Correct 1212 ms 16004 KB Output is correct
63 Correct 1460 ms 15612 KB Output is correct
64 Correct 1300 ms 17168 KB Output is correct
65 Correct 1307 ms 15284 KB Output is correct
66 Correct 1268 ms 16164 KB Output is correct
67 Correct 1231 ms 14692 KB Output is correct
68 Correct 1424 ms 17844 KB Output is correct
69 Correct 346 ms 29128 KB Output is correct
70 Correct 316 ms 27840 KB Output is correct
71 Correct 383 ms 31056 KB Output is correct
72 Correct 326 ms 15776 KB Output is correct
73 Correct 328 ms 16560 KB Output is correct
74 Correct 383 ms 18244 KB Output is correct
75 Correct 788 ms 16556 KB Output is correct
76 Correct 820 ms 17020 KB Output is correct
77 Correct 773 ms 16480 KB Output is correct
78 Correct 750 ms 17264 KB Output is correct