44792023-03-28 13:12:08ZsofiaKeresztelyTársaság (50)cpp14Wrong answer 7/5017ms4856 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, int 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/03ms1872 KiB
2Wrong answer0/08ms2584 KiB
3Wrong answer0/33ms2412 KiB
4Wrong answer0/33ms2492 KiB
5Accepted3/33ms2708 KiB
6Wrong answer0/33ms2928 KiB
7Wrong answer0/33ms3172 KiB
8Wrong answer0/33ms3508 KiB
9Wrong answer0/34ms3628 KiB
10Wrong answer0/36ms3896 KiB
11Wrong answer0/37ms4320 KiB
12Wrong answer0/38ms4580 KiB
13Wrong answer0/49ms4560 KiB
14Wrong answer0/412ms4688 KiB
15Wrong answer0/413ms4656 KiB
16Accepted4/414ms4844 KiB
17Wrong answer0/417ms4856 KiB