Submission #545514

# Submission time Handle Problem Language Result Execution time Memory
545514 2022-04-04T17:14:40 Z mat50013 Parkovi (COCI22_parkovi) C++11
110 / 110
1031 ms 34832 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const int NMAX(200005);
const ll MAXX(1e16);
vector<pair<int, int> > G[NMAX];
vector<int> aux;
int n, k, fr[NMAX];
ll dis[NMAX];

inline pair<ll, ll> DFS(int nod, int tata, ll cat, ll dUnd)
{
    pair<ll, ll> sol = {MAXX, -MAXX};
    for(auto it: G[nod])
        if(it.first != tata)
        {
            auto ce = DFS(it.first, nod, cat, it.second);
            if(ce.first != MAXX)
                sol.first = min(sol.first, ce.first + it.second);
            if(ce.second != -MAXX)
                sol.second = max(sol.second, ce.second + it.second);
        }
    if(sol.first > cat && sol.second < 0)
    {
        sol.first = MAXX;
        sol.second = 0;
    }
    if(sol.first != MAXX && sol.second != -MAXX && sol.first + sol.second <= cat)
    {
        sol.second = -MAXX;
        return sol;
    }
    if((sol.second != -MAXX && sol.second > cat) || (sol.second != -MAXX && sol.second + dUnd > cat) || (nod == 1 && sol.second >= 0))
    {
        aux.push_back(nod);
        return {0, -MAXX};
    }
    return sol;
}

inline bool test(ll mij, int nr)
{
    aux.clear();
    DFS(1, -1, mij, 0);
    return ((int)aux.size() <= nr);
}

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

    cin >> n >> k;

    for(int i = 1; i < n; ++i)
    {
        int x, y, c;
        cin >> x >> y >> c;
        G[x].push_back({y, c});
        G[y].push_back({x, c});
    }

    vector<int> sol;
    ll st = 0, dr = 1e16, best = 0;
    while(st <= dr)
    {
        ll mij = st + (dr - st) / 2;
        if(test(mij, k))
        {
            best = mij;
            sol = aux;
            dr = mij - 1;
        }
        else st = mij + 1;
    }

    cout << best << '\n';
    for(auto it: sol)
        fr[it] = 1;
    for(int i = 1; i <= n && (int)sol.size() < k; ++i)
        if(fr[i] == 0)
            sol.push_back(i);
    for(auto it: sol)
        cout << it << ' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 2 ms 5020 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 28516 KB Output is correct
2 Correct 352 ms 29248 KB Output is correct
3 Correct 226 ms 13724 KB Output is correct
4 Correct 890 ms 12004 KB Output is correct
5 Correct 825 ms 11780 KB Output is correct
6 Correct 824 ms 11784 KB Output is correct
7 Correct 832 ms 11776 KB Output is correct
8 Correct 890 ms 12212 KB Output is correct
9 Correct 863 ms 11988 KB Output is correct
10 Correct 934 ms 12108 KB Output is correct
11 Correct 603 ms 13412 KB Output is correct
12 Correct 563 ms 13900 KB Output is correct
13 Correct 630 ms 14552 KB Output is correct
14 Correct 554 ms 13580 KB Output is correct
15 Correct 555 ms 13096 KB Output is correct
16 Correct 578 ms 13784 KB Output is correct
17 Correct 566 ms 13160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 366 ms 29552 KB Output is correct
2 Correct 352 ms 28868 KB Output is correct
3 Correct 318 ms 27560 KB Output is correct
4 Correct 336 ms 27484 KB Output is correct
5 Correct 364 ms 32056 KB Output is correct
6 Correct 381 ms 31564 KB Output is correct
7 Correct 402 ms 32688 KB Output is correct
8 Correct 368 ms 29820 KB Output is correct
9 Correct 365 ms 29452 KB Output is correct
10 Correct 346 ms 28992 KB Output is correct
11 Correct 331 ms 28112 KB Output is correct
12 Correct 403 ms 32884 KB Output is correct
13 Correct 398 ms 33112 KB Output is correct
14 Correct 405 ms 31524 KB Output is correct
15 Correct 342 ms 28980 KB Output is correct
16 Correct 327 ms 28000 KB Output is correct
17 Correct 323 ms 27852 KB Output is correct
18 Correct 341 ms 29136 KB Output is correct
19 Correct 337 ms 31540 KB Output is correct
20 Correct 364 ms 31624 KB Output is correct
21 Correct 350 ms 30772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 2 ms 5020 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 351 ms 28516 KB Output is correct
16 Correct 352 ms 29248 KB Output is correct
17 Correct 226 ms 13724 KB Output is correct
18 Correct 890 ms 12004 KB Output is correct
19 Correct 825 ms 11780 KB Output is correct
20 Correct 824 ms 11784 KB Output is correct
21 Correct 832 ms 11776 KB Output is correct
22 Correct 890 ms 12212 KB Output is correct
23 Correct 863 ms 11988 KB Output is correct
24 Correct 934 ms 12108 KB Output is correct
25 Correct 603 ms 13412 KB Output is correct
26 Correct 563 ms 13900 KB Output is correct
27 Correct 630 ms 14552 KB Output is correct
28 Correct 554 ms 13580 KB Output is correct
29 Correct 555 ms 13096 KB Output is correct
30 Correct 578 ms 13784 KB Output is correct
31 Correct 566 ms 13160 KB Output is correct
32 Correct 366 ms 29552 KB Output is correct
33 Correct 352 ms 28868 KB Output is correct
34 Correct 318 ms 27560 KB Output is correct
35 Correct 336 ms 27484 KB Output is correct
36 Correct 364 ms 32056 KB Output is correct
37 Correct 381 ms 31564 KB Output is correct
38 Correct 402 ms 32688 KB Output is correct
39 Correct 368 ms 29820 KB Output is correct
40 Correct 365 ms 29452 KB Output is correct
41 Correct 346 ms 28992 KB Output is correct
42 Correct 331 ms 28112 KB Output is correct
43 Correct 403 ms 32884 KB Output is correct
44 Correct 398 ms 33112 KB Output is correct
45 Correct 405 ms 31524 KB Output is correct
46 Correct 342 ms 28980 KB Output is correct
47 Correct 327 ms 28000 KB Output is correct
48 Correct 323 ms 27852 KB Output is correct
49 Correct 341 ms 29136 KB Output is correct
50 Correct 337 ms 31540 KB Output is correct
51 Correct 364 ms 31624 KB Output is correct
52 Correct 350 ms 30772 KB Output is correct
53 Correct 888 ms 14664 KB Output is correct
54 Correct 941 ms 14924 KB Output is correct
55 Correct 966 ms 15176 KB Output is correct
56 Correct 958 ms 15976 KB Output is correct
57 Correct 950 ms 17148 KB Output is correct
58 Correct 914 ms 14732 KB Output is correct
59 Correct 1000 ms 20076 KB Output is correct
60 Correct 946 ms 15096 KB Output is correct
61 Correct 811 ms 14504 KB Output is correct
62 Correct 840 ms 16888 KB Output is correct
63 Correct 983 ms 15308 KB Output is correct
64 Correct 925 ms 18324 KB Output is correct
65 Correct 953 ms 14984 KB Output is correct
66 Correct 932 ms 17052 KB Output is correct
67 Correct 875 ms 14536 KB Output is correct
68 Correct 1031 ms 18964 KB Output is correct
69 Correct 334 ms 31788 KB Output is correct
70 Correct 320 ms 30540 KB Output is correct
71 Correct 388 ms 34832 KB Output is correct
72 Correct 207 ms 15848 KB Output is correct
73 Correct 215 ms 15800 KB Output is correct
74 Correct 260 ms 18540 KB Output is correct
75 Correct 605 ms 16696 KB Output is correct
76 Correct 649 ms 16904 KB Output is correct
77 Correct 592 ms 16584 KB Output is correct
78 Correct 604 ms 18248 KB Output is correct