Submission #881476

# Submission time Handle Problem Language Result Execution time Memory
881476 2023-12-01T09:30:42 Z Yang8on Parkovi (COCI22_parkovi) C++14
110 / 110
1407 ms 39120 KB
#include <bits/stdc++.h>

#define Yang8on Nguyen_Dinh_Son
#define sonphamay Nguyen_Dinh_Son

#define aothtday "aog"
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define endl '\n'
#define pii pair<int, ll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define maxn 200005
#define maxm
#define maxx
#define mod 1000000007
#define base 311
#define ModHas 1000000003ll
#define gb(i, j) ((i >> j) & 1)
#define int long long

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll GetRandom(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r)(rng);
}

const ll oo = 1e18;

int n, k;
ll lim, sl;
ll dis[maxn], reach[maxn], place[maxn];
vector<pii> o[maxn];
/// reach[u] : khoảng cách xa nhất đến 1 đỉnh chưa được bao phủ (gọi đỉnh đấy là u, tức u đến 1 đỉnh
void dfs(int u, int par)
{
    for(pii x : o[u])
    {
        int v = x.f;
        ll w = x.s;

        if(v == par) continue;

        dfs(v, u);

        if(reach[v] + min(w, dis[v]) <= lim)
        {
            if(reach[v] + dis[v] > lim) reach[u] = max(reach[u], reach[v] + w);
            dis[u] = min(dis[u], dis[v] + w);
        }
        else
        {
            place[v] = 1, sl ++;
            dis[u] = min(dis[u], w);
        }
    }
}

bool calc(int mid)
{
    fi(i, 1, n) dis[i] = oo, reach[i] = 0, place[i] = 0;

    lim = mid, sl = 0;
    dfs(1, -1);

    if(dis[1] + reach[1] > lim) place[1] = 1, sl ++;

    if(sl > k) return false;
    return true;
}

void solve()
{
    cin >> n >> k;
    fi(i, 1, n - 1)
    {
        int x, y;
        ll w;
        cin >> x >> y >> w;
        o[x].pb({y, w});
        o[y].pb({x, w});
    }

    int l = 0, r = oo;
    while(l <= r)
    {
        int mid = (l + r) >> 1;

        if(calc(mid)) r = mid - 1;
        else l = mid + 1;
    }

    bool check = calc(l);
    sl = 0;
    fi(i, 1, n) if(place[i]) sl ++;

    cout << l << '\n';

    fi(i, 1, n)
    {
        if(place[i]) cout << i << ' ';
        else if(sl < k) sl ++, cout << i << ' ';
    }
}

signed main()
{
    if(fopen(aothtday".inp", "r"))
    {
        freopen(aothtday".inp","r",stdin);
        freopen(aothtday".out","w",stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int nTest = 1;
//    cin >> nTest;

    while(nTest --)
    {
        solve();
    }

    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:99:10: warning: unused variable 'check' [-Wunused-variable]
   99 |     bool check = calc(l);
      |          ^~~~~
Main.cpp: In function 'int main()':
Main.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(aothtday".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(aothtday".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8852 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 342 ms 36032 KB Output is correct
2 Correct 332 ms 38172 KB Output is correct
3 Correct 284 ms 23476 KB Output is correct
4 Correct 1182 ms 23496 KB Output is correct
5 Correct 973 ms 23024 KB Output is correct
6 Correct 1108 ms 23024 KB Output is correct
7 Correct 1016 ms 21844 KB Output is correct
8 Correct 1253 ms 22572 KB Output is correct
9 Correct 971 ms 22868 KB Output is correct
10 Correct 984 ms 23248 KB Output is correct
11 Correct 797 ms 24856 KB Output is correct
12 Correct 754 ms 24748 KB Output is correct
13 Correct 941 ms 26296 KB Output is correct
14 Correct 657 ms 23288 KB Output is correct
15 Correct 684 ms 22892 KB Output is correct
16 Correct 768 ms 24144 KB Output is correct
17 Correct 671 ms 23576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 38492 KB Output is correct
2 Correct 336 ms 37852 KB Output is correct
3 Correct 337 ms 36332 KB Output is correct
4 Correct 321 ms 36364 KB Output is correct
5 Correct 334 ms 38468 KB Output is correct
6 Correct 367 ms 38180 KB Output is correct
7 Correct 364 ms 39120 KB Output is correct
8 Correct 383 ms 38236 KB Output is correct
9 Correct 357 ms 37972 KB Output is correct
10 Correct 348 ms 37204 KB Output is correct
11 Correct 332 ms 36436 KB Output is correct
12 Correct 384 ms 38864 KB Output is correct
13 Correct 376 ms 39000 KB Output is correct
14 Correct 375 ms 38488 KB Output is correct
15 Correct 346 ms 36624 KB Output is correct
16 Correct 304 ms 35408 KB Output is correct
17 Correct 347 ms 35156 KB Output is correct
18 Correct 367 ms 36908 KB Output is correct
19 Correct 332 ms 36436 KB Output is correct
20 Correct 433 ms 36984 KB Output is correct
21 Correct 384 ms 36292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8852 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 342 ms 36032 KB Output is correct
16 Correct 332 ms 38172 KB Output is correct
17 Correct 284 ms 23476 KB Output is correct
18 Correct 1182 ms 23496 KB Output is correct
19 Correct 973 ms 23024 KB Output is correct
20 Correct 1108 ms 23024 KB Output is correct
21 Correct 1016 ms 21844 KB Output is correct
22 Correct 1253 ms 22572 KB Output is correct
23 Correct 971 ms 22868 KB Output is correct
24 Correct 984 ms 23248 KB Output is correct
25 Correct 797 ms 24856 KB Output is correct
26 Correct 754 ms 24748 KB Output is correct
27 Correct 941 ms 26296 KB Output is correct
28 Correct 657 ms 23288 KB Output is correct
29 Correct 684 ms 22892 KB Output is correct
30 Correct 768 ms 24144 KB Output is correct
31 Correct 671 ms 23576 KB Output is correct
32 Correct 348 ms 38492 KB Output is correct
33 Correct 336 ms 37852 KB Output is correct
34 Correct 337 ms 36332 KB Output is correct
35 Correct 321 ms 36364 KB Output is correct
36 Correct 334 ms 38468 KB Output is correct
37 Correct 367 ms 38180 KB Output is correct
38 Correct 364 ms 39120 KB Output is correct
39 Correct 383 ms 38236 KB Output is correct
40 Correct 357 ms 37972 KB Output is correct
41 Correct 348 ms 37204 KB Output is correct
42 Correct 332 ms 36436 KB Output is correct
43 Correct 384 ms 38864 KB Output is correct
44 Correct 376 ms 39000 KB Output is correct
45 Correct 375 ms 38488 KB Output is correct
46 Correct 346 ms 36624 KB Output is correct
47 Correct 304 ms 35408 KB Output is correct
48 Correct 347 ms 35156 KB Output is correct
49 Correct 367 ms 36908 KB Output is correct
50 Correct 332 ms 36436 KB Output is correct
51 Correct 433 ms 36984 KB Output is correct
52 Correct 384 ms 36292 KB Output is correct
53 Correct 1051 ms 23372 KB Output is correct
54 Correct 1051 ms 23716 KB Output is correct
55 Correct 1316 ms 24500 KB Output is correct
56 Correct 1120 ms 24064 KB Output is correct
57 Correct 1179 ms 24232 KB Output is correct
58 Correct 1034 ms 23504 KB Output is correct
59 Correct 1158 ms 25296 KB Output is correct
60 Correct 1087 ms 23036 KB Output is correct
61 Correct 1045 ms 21700 KB Output is correct
62 Correct 930 ms 22156 KB Output is correct
63 Correct 1207 ms 23104 KB Output is correct
64 Correct 1163 ms 23172 KB Output is correct
65 Correct 1012 ms 23372 KB Output is correct
66 Correct 925 ms 23312 KB Output is correct
67 Correct 866 ms 22488 KB Output is correct
68 Correct 1407 ms 24616 KB Output is correct
69 Correct 395 ms 38068 KB Output is correct
70 Correct 343 ms 35904 KB Output is correct
71 Correct 371 ms 38812 KB Output is correct
72 Correct 235 ms 22716 KB Output is correct
73 Correct 315 ms 22052 KB Output is correct
74 Correct 313 ms 23476 KB Output is correct
75 Correct 739 ms 25176 KB Output is correct
76 Correct 880 ms 24660 KB Output is correct
77 Correct 747 ms 24516 KB Output is correct
78 Correct 750 ms 23888 KB Output is correct