답안 #533524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533524 2022-03-06T08:54:37 Z Vimmer Parkovi (COCI22_parkovi) C++14
110 / 110
2085 ms 46348 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")

#define F first
#define S second
#define PB push_back
#define M ll(1e9 + 7)
#define sz(x) int(x.size())
#define N 200005
#define pri(x) cout << x << endl
//#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

using namespace std;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;

int n, k;

vector <pair <int, int> > g[N];

bool go;

ll md;

int ost;

bool cmp(pair <ll, ll> x, pair <ll, ll> y)
{
    return x.S < y.S;
}

set <int> ans;

pair <ll, ll> dfs(int v, int p, ll dst)
{
    ll mx = 0;

    ll when = 1e18;

    vector <pair <ll, ll> > vr; vr.clear();

    for (auto it : g[v])
    {
        if (it.F == p)
            continue;

        pair <ll, ll> vl = dfs(it.F, v, it.S);

        vr.PB(vl);
    }

    sort(all(vr), cmp);

    for (int i = 0; i < sz(vr); i++)
    {
        if (vr[0].S + vr[i].F > md)
            mx = max(mx, vr[i].F);
    }

    if (sz(vr))
        when = vr[0].S;

//    pri(v _ mx _ when _ ost _ dst);

    if (mx + dst > md && (mx != 0 || when > md))
    {
        if (go)
            ans.insert(v);

        ost--;

        when = 0;

        mx = 0;
    }

    if (v == 1 && (mx != 0 || when > md))
    {
        ost--;

        return {mx, when};
    }

//    pri(v _ mx _ when _ ost _ dst);
    mx += dst;

    if (mx == dst && when <= md)
        mx = 0;

    if (when != 1e18)
        when += dst;

    if (when > md)
        when = 1e18;

    return {mx, when};
}

int main()
{
    istream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    freopen("1.in", "r", stdin);

    cin >> n >> k;

    for (int i = 1; i < n; i++)
    {
        int x, y, w;

        cin >> x >> y >> w;

        g[x].PB({y, w});

        g[y].PB({x, w});
    }

    ll l = 1, r = 1e18;

    while (l < r)
    {
        md = (l + r) / 2;

        ost = k;

        dfs(1, -1, 0);

        if (ost >= 0)
            r = md;
                else l = md + 1;
    }

    md = l;

    go = 1;

    dfs(1, -1, 0);

    pri(l);

    int i = 1;

    while (sz(ans) < k)
    {
        ans.insert(i++);
    }

    for (auto it : ans)
        cout << it << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 3 ms 4940 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 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 2 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 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 776 ms 31412 KB Output is correct
2 Correct 825 ms 36376 KB Output is correct
3 Correct 951 ms 24700 KB Output is correct
4 Correct 1935 ms 16148 KB Output is correct
5 Correct 2085 ms 15788 KB Output is correct
6 Correct 1771 ms 15800 KB Output is correct
7 Correct 1731 ms 14588 KB Output is correct
8 Correct 1868 ms 15132 KB Output is correct
9 Correct 1861 ms 15540 KB Output is correct
10 Correct 1868 ms 15800 KB Output is correct
11 Correct 1247 ms 18072 KB Output is correct
12 Correct 1099 ms 18024 KB Output is correct
13 Correct 1285 ms 19736 KB Output is correct
14 Correct 1133 ms 16908 KB Output is correct
15 Correct 1117 ms 16240 KB Output is correct
16 Correct 1143 ms 17852 KB Output is correct
17 Correct 1125 ms 16932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 827 ms 32608 KB Output is correct
2 Correct 798 ms 36072 KB Output is correct
3 Correct 746 ms 34496 KB Output is correct
4 Correct 754 ms 34504 KB Output is correct
5 Correct 858 ms 45480 KB Output is correct
6 Correct 854 ms 40772 KB Output is correct
7 Correct 898 ms 42692 KB Output is correct
8 Correct 825 ms 36496 KB Output is correct
9 Correct 807 ms 36292 KB Output is correct
10 Correct 806 ms 35592 KB Output is correct
11 Correct 757 ms 34456 KB Output is correct
12 Correct 915 ms 46348 KB Output is correct
13 Correct 893 ms 43972 KB Output is correct
14 Correct 893 ms 40572 KB Output is correct
15 Correct 795 ms 34884 KB Output is correct
16 Correct 741 ms 33600 KB Output is correct
17 Correct 768 ms 32772 KB Output is correct
18 Correct 803 ms 32368 KB Output is correct
19 Correct 809 ms 40492 KB Output is correct
20 Correct 836 ms 39032 KB Output is correct
21 Correct 798 ms 36852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 3 ms 4940 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 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 2 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 3 ms 4940 KB Output is correct
15 Correct 776 ms 31412 KB Output is correct
16 Correct 825 ms 36376 KB Output is correct
17 Correct 951 ms 24700 KB Output is correct
18 Correct 1935 ms 16148 KB Output is correct
19 Correct 2085 ms 15788 KB Output is correct
20 Correct 1771 ms 15800 KB Output is correct
21 Correct 1731 ms 14588 KB Output is correct
22 Correct 1868 ms 15132 KB Output is correct
23 Correct 1861 ms 15540 KB Output is correct
24 Correct 1868 ms 15800 KB Output is correct
25 Correct 1247 ms 18072 KB Output is correct
26 Correct 1099 ms 18024 KB Output is correct
27 Correct 1285 ms 19736 KB Output is correct
28 Correct 1133 ms 16908 KB Output is correct
29 Correct 1117 ms 16240 KB Output is correct
30 Correct 1143 ms 17852 KB Output is correct
31 Correct 1125 ms 16932 KB Output is correct
32 Correct 827 ms 32608 KB Output is correct
33 Correct 798 ms 36072 KB Output is correct
34 Correct 746 ms 34496 KB Output is correct
35 Correct 754 ms 34504 KB Output is correct
36 Correct 858 ms 45480 KB Output is correct
37 Correct 854 ms 40772 KB Output is correct
38 Correct 898 ms 42692 KB Output is correct
39 Correct 825 ms 36496 KB Output is correct
40 Correct 807 ms 36292 KB Output is correct
41 Correct 806 ms 35592 KB Output is correct
42 Correct 757 ms 34456 KB Output is correct
43 Correct 915 ms 46348 KB Output is correct
44 Correct 893 ms 43972 KB Output is correct
45 Correct 893 ms 40572 KB Output is correct
46 Correct 795 ms 34884 KB Output is correct
47 Correct 741 ms 33600 KB Output is correct
48 Correct 768 ms 32772 KB Output is correct
49 Correct 803 ms 32368 KB Output is correct
50 Correct 809 ms 40492 KB Output is correct
51 Correct 836 ms 39032 KB Output is correct
52 Correct 798 ms 36852 KB Output is correct
53 Correct 1729 ms 12300 KB Output is correct
54 Correct 1814 ms 12428 KB Output is correct
55 Correct 1991 ms 12740 KB Output is correct
56 Correct 1977 ms 13048 KB Output is correct
57 Correct 2051 ms 16500 KB Output is correct
58 Correct 1810 ms 12292 KB Output is correct
59 Correct 1998 ms 22928 KB Output is correct
60 Correct 1930 ms 12712 KB Output is correct
61 Correct 1682 ms 11940 KB Output is correct
62 Correct 1772 ms 16916 KB Output is correct
63 Correct 1991 ms 12764 KB Output is correct
64 Correct 1881 ms 22160 KB Output is correct
65 Correct 1867 ms 12652 KB Output is correct
66 Correct 1925 ms 17160 KB Output is correct
67 Correct 1748 ms 15252 KB Output is correct
68 Correct 2074 ms 26384 KB Output is correct
69 Correct 828 ms 36340 KB Output is correct
70 Correct 743 ms 33732 KB Output is correct
71 Correct 889 ms 41540 KB Output is correct
72 Correct 867 ms 23764 KB Output is correct
73 Correct 894 ms 23132 KB Output is correct
74 Correct 958 ms 24740 KB Output is correct
75 Correct 1155 ms 18804 KB Output is correct
76 Correct 1285 ms 17868 KB Output is correct
77 Correct 1164 ms 18016 KB Output is correct
78 Correct 1176 ms 19032 KB Output is correct