149262025-02-07 21:07:52szjTársaság (50)cpp17Runtime error 0/501ms508 KiB
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
struct fa
{
    int p, l;
};
vector<vector<fa>> vec;
ll koz = 0;
int num = 0;
long long int req(int s)
{
    ll ma = 0, ert = 0;
    for(int i=0; i<vec[s].size(); i++)
    {
        ert = req(vec[s][i].p)+vec[s][i].l;
        if(ert > koz)
        {
            ert = 0;
            num++;
        }
        ma = max(ma, ert);
    }
    return ma;
}
int main()
{
    ifstream cin("f.txt");
    int n, m, i, el = 0, c, j;
    fa csucs;
    cin >> n >> m;
    vec.resize(n+1);
    for(i=1; i<n; i++)
    {
        cin >> c >> csucs.l;
        csucs.p = i+1;
        vec[c].push_back(csucs);
    }
    ll al = 0, fel = 1e13;
    while(al < fel)
    {
        koz = (al+fel)/2;
        req(1);
        if(num<=m)fel = koz;
        else
        {
            al = koz;
            if(al+1==fel)break;
        }
        num = 0;
    }
    cout << fel;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Runtime error0/01ms316 KiB
2Runtime error0/01ms316 KiB
3Runtime error0/31ms316 KiB
4Runtime error0/31ms316 KiB
5Runtime error0/31ms508 KiB
6Runtime error0/31ms316 KiB
7Runtime error0/31ms316 KiB
8Runtime error0/31ms316 KiB
9Runtime error0/31ms392 KiB
10Runtime error0/31ms316 KiB
11Runtime error0/31ms316 KiB
12Runtime error0/31ms316 KiB
13Runtime error0/41ms508 KiB
14Runtime error0/41ms500 KiB
15Runtime error0/41ms316 KiB
16Runtime error0/41ms316 KiB
17Runtime error0/41ms316 KiB