Submission #849026

# Submission time Handle Problem Language Result Execution time Memory
849026 2023-09-13T23:47:05 Z tiwerlol Parkovi (COCI22_parkovi) C++17
110 / 110
1300 ms 56884 KB
#include <bits/stdc++.h>
using namespace std;

ofstream fout("xor.out");
ifstream fin("xor.in");

#define miauDebug
#ifdef miauDebug
#define mau(x) MIAUMIAU(#x, x)
#else
#define mau(x)
#endif

void MIAUMIAU(const char* var_name, auto var_value) {
    cout << var_name << " = " << var_value << endl;
}

using ll = long long;
const int nM = 2e5+5;
const ll MOD = 1e9 + 7;
// :3

vector<vector<pair<int, ll>>> node;
vector<ll> dist(nM), reach(nM), ans;
int f;
void dfs(int a, int p, ll mid, ll c, bool sw)
{
    reach[a]=- 6e17;
    dist[a] =  6e17;

    for(auto x : node[a])
    {
        if(x.first!=p)
        {
            dfs(x.first, a, mid, x.second, sw);
            reach[a] = max(reach[x.first] + x.second, reach[a]);
            dist[a] = min(dist[x.first] + x.second, dist[a]);
        }
    }

    if(dist[a] > mid && reach[a] < 0)
        reach[a] = 0;

    if(dist[a] + reach[a] <= mid)
    {
        reach[a]=- 6e17;
        return;
    }

    if(reach[a] + c > mid || (a==1 && (reach[a] >= 0)))
    {
        if(sw)
        {
            ans.push_back(a);
        }
        f++;
        reach[a] = - 6e17;
        dist[a] = 0;
    }
}

void solve() {
    int n, k; cin >> n >> k;

    node = vector<vector<pair<int, ll>>> (n+2);

    for(int z = 1; z < n; z++)
    {
        int a, b, w; cin >> a >> b >> w;

        node[a].push_back(make_pair(b, w));
        node[b].push_back(make_pair(a, w));
    }

    ll l = 0, r = 1e16;
    ll mn = 1e16;

    while(l<=r)
    {
        ll mid = (l+r)/2;
        dfs(1, 0, mid, 0, 0);

        if(f <= k)
        {
            mn = mid;
            r = mid-1;
        } else
        {
            l = mid+1;
        }
        f = 0;
    }

    cout << mn << '\n';

    dfs(1, 0, mn, 0, 1);
    map<int, int> miau;
    for(auto x : ans)
        miau[x]=1;
    if(ans.size()==k)
    {
        for(auto x : ans)
            cout << x << ' ';
        return;
    }

    for(int z = 1; z <= n; z++)
    {
        if(!miau[z]) ans.push_back(z);
        if(ans.size()==k)
        {
            for(auto x : ans)
                cout << x << ' ';
            return;
        }
    }
}
signed main()
{
    cout.tie(NULL);
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int tt = 1; //cin >> tt;

    while(tt--)
        solve();
}

Compilation message

Main.cpp:14:37: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   14 | void MIAUMIAU(const char* var_name, auto var_value) {
      |                                     ^~~~
Main.cpp: In function 'void solve()':
Main.cpp:100:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |     if(ans.size()==k)
      |        ~~~~~~~~~~^~~
Main.cpp:110:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  110 |         if(ans.size()==k)
      |            ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3416 KB Output is correct
8 Correct 2 ms 3424 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3416 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 2 ms 3588 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 40280 KB Output is correct
2 Correct 407 ms 45564 KB Output is correct
3 Correct 285 ms 22108 KB Output is correct
4 Correct 858 ms 21760 KB Output is correct
5 Correct 956 ms 21176 KB Output is correct
6 Correct 826 ms 21388 KB Output is correct
7 Correct 1032 ms 20032 KB Output is correct
8 Correct 1060 ms 21072 KB Output is correct
9 Correct 1002 ms 21320 KB Output is correct
10 Correct 958 ms 21584 KB Output is correct
11 Correct 727 ms 23976 KB Output is correct
12 Correct 715 ms 24032 KB Output is correct
13 Correct 890 ms 26096 KB Output is correct
14 Correct 640 ms 22292 KB Output is correct
15 Correct 687 ms 21844 KB Output is correct
16 Correct 693 ms 23576 KB Output is correct
17 Correct 659 ms 22624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 442 ms 41948 KB Output is correct
2 Correct 434 ms 45124 KB Output is correct
3 Correct 402 ms 43148 KB Output is correct
4 Correct 391 ms 42908 KB Output is correct
5 Correct 455 ms 55748 KB Output is correct
6 Correct 471 ms 50724 KB Output is correct
7 Correct 469 ms 52948 KB Output is correct
8 Correct 449 ms 45904 KB Output is correct
9 Correct 425 ms 45392 KB Output is correct
10 Correct 437 ms 44888 KB Output is correct
11 Correct 411 ms 43088 KB Output is correct
12 Correct 511 ms 56884 KB Output is correct
13 Correct 459 ms 54424 KB Output is correct
14 Correct 448 ms 50336 KB Output is correct
15 Correct 394 ms 43940 KB Output is correct
16 Correct 356 ms 42256 KB Output is correct
17 Correct 380 ms 42104 KB Output is correct
18 Correct 428 ms 44020 KB Output is correct
19 Correct 420 ms 52960 KB Output is correct
20 Correct 466 ms 51652 KB Output is correct
21 Correct 411 ms 49144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3416 KB Output is correct
8 Correct 2 ms 3424 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3416 KB Output is correct
11 Correct 1 ms 3420 KB Output is correct
12 Correct 2 ms 3588 KB Output is correct
13 Correct 1 ms 3420 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
15 Correct 391 ms 40280 KB Output is correct
16 Correct 407 ms 45564 KB Output is correct
17 Correct 285 ms 22108 KB Output is correct
18 Correct 858 ms 21760 KB Output is correct
19 Correct 956 ms 21176 KB Output is correct
20 Correct 826 ms 21388 KB Output is correct
21 Correct 1032 ms 20032 KB Output is correct
22 Correct 1060 ms 21072 KB Output is correct
23 Correct 1002 ms 21320 KB Output is correct
24 Correct 958 ms 21584 KB Output is correct
25 Correct 727 ms 23976 KB Output is correct
26 Correct 715 ms 24032 KB Output is correct
27 Correct 890 ms 26096 KB Output is correct
28 Correct 640 ms 22292 KB Output is correct
29 Correct 687 ms 21844 KB Output is correct
30 Correct 693 ms 23576 KB Output is correct
31 Correct 659 ms 22624 KB Output is correct
32 Correct 442 ms 41948 KB Output is correct
33 Correct 434 ms 45124 KB Output is correct
34 Correct 402 ms 43148 KB Output is correct
35 Correct 391 ms 42908 KB Output is correct
36 Correct 455 ms 55748 KB Output is correct
37 Correct 471 ms 50724 KB Output is correct
38 Correct 469 ms 52948 KB Output is correct
39 Correct 449 ms 45904 KB Output is correct
40 Correct 425 ms 45392 KB Output is correct
41 Correct 437 ms 44888 KB Output is correct
42 Correct 411 ms 43088 KB Output is correct
43 Correct 511 ms 56884 KB Output is correct
44 Correct 459 ms 54424 KB Output is correct
45 Correct 448 ms 50336 KB Output is correct
46 Correct 394 ms 43940 KB Output is correct
47 Correct 356 ms 42256 KB Output is correct
48 Correct 380 ms 42104 KB Output is correct
49 Correct 428 ms 44020 KB Output is correct
50 Correct 420 ms 52960 KB Output is correct
51 Correct 466 ms 51652 KB Output is correct
52 Correct 411 ms 49144 KB Output is correct
53 Correct 769 ms 21796 KB Output is correct
54 Correct 975 ms 22152 KB Output is correct
55 Correct 1098 ms 22948 KB Output is correct
56 Correct 1105 ms 22948 KB Output is correct
57 Correct 935 ms 26800 KB Output is correct
58 Correct 1006 ms 21788 KB Output is correct
59 Correct 1300 ms 34384 KB Output is correct
60 Correct 1254 ms 21484 KB Output is correct
61 Correct 766 ms 20052 KB Output is correct
62 Correct 973 ms 25568 KB Output is correct
63 Correct 1088 ms 21584 KB Output is correct
64 Correct 988 ms 31780 KB Output is correct
65 Correct 1122 ms 21740 KB Output is correct
66 Correct 898 ms 26564 KB Output is correct
67 Correct 1111 ms 20876 KB Output is correct
68 Correct 1117 ms 33788 KB Output is correct
69 Correct 395 ms 45388 KB Output is correct
70 Correct 393 ms 42676 KB Output is correct
71 Correct 483 ms 51504 KB Output is correct
72 Correct 244 ms 22092 KB Output is correct
73 Correct 330 ms 20416 KB Output is correct
74 Correct 309 ms 26904 KB Output is correct
75 Correct 698 ms 24656 KB Output is correct
76 Correct 769 ms 24120 KB Output is correct
77 Correct 710 ms 23892 KB Output is correct
78 Correct 725 ms 25428 KB Output is correct