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

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

int main()
{
    ll n, k;
    cin >> n >> k;
    g.resize(n+1);
    for (ll i=2; i<=n; i++){
        ll 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/03ms1876 KiB
2Wrong answer0/08ms2620 KiB
3Wrong answer0/33ms2488 KiB
4Wrong answer0/33ms2560 KiB
5Accepted3/33ms2752 KiB
6Wrong answer0/33ms2988 KiB
7Wrong answer0/33ms3264 KiB
8Wrong answer0/34ms3260 KiB
9Wrong answer0/34ms3316 KiB
10Wrong answer0/36ms3620 KiB
11Wrong answer0/37ms3756 KiB
12Wrong answer0/38ms3844 KiB
13Wrong answer0/49ms3836 KiB
14Wrong answer0/412ms3992 KiB
15Wrong answer0/413ms4276 KiB
16Accepted4/414ms4524 KiB
17Wrong answer0/417ms4580 KiB