44812023-03-28 13:21:14ZsofiaKeresztelyTársaság (50)cpp14Wrong answer 7/5017ms4668 KiB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
typedef long long ll;
vector<vector<pii> > g;

int restarts(int v, ll val, ll d){
    int r = (d > val);
    d = d * (d <= val);
    for (pii x : g[v]){
        r += restarts(x.fi, val, d + x.se);
    }
    return r;
}

int main()
{
    int n, k;
    cin >> n >> k;
    g.resize(n+1);
    for (int i=2; i<=n; i++){
        int a, b;
        cin >> a >> b;
        g[a].push_back({i, b});
    }
    ll l = -1, r = 1e13;
    while (l + 1 < r){
        ll m = (l + r) / 2;
        if (restarts(1, m, 0) > k){
            l = m;
        }
        else{
            r = m;
        }
    }
    cout << r;
}
SubtaskSumTestVerdictTimeMemory
base7/50
1Wrong answer0/03ms1880 KiB
2Wrong answer0/08ms2524 KiB
3Wrong answer0/33ms2280 KiB
4Wrong answer0/33ms2496 KiB
5Accepted3/33ms2708 KiB
6Wrong answer0/33ms2952 KiB
7Wrong answer0/33ms3320 KiB
8Wrong answer0/33ms3284 KiB
9Wrong answer0/34ms3732 KiB
10Wrong answer0/36ms3584 KiB
11Wrong answer0/37ms3680 KiB
12Wrong answer0/38ms3808 KiB
13Wrong answer0/410ms3836 KiB
14Wrong answer0/412ms3848 KiB
15Wrong answer0/414ms3864 KiB
16Accepted4/416ms4320 KiB
17Wrong answer0/417ms4668 KiB