230562026-01-16 11:24:06ercseferencTársaság (50)cpp17Wrong answer 43/5019ms952 KiB
#include <bits/stdc++.h>
using namespace std;
int n,k,l;
struct munk{vector<int>kim; int fon;};
vector<munk>a;
long long tav(int x, long long maxh){
    long long d=0;
    for(int i:a[x].kim){
        d=max(d, tav(i,maxh)+a[i].fon);}
    if(d+a[x].fon>maxh){
        l++; return -a[x].fon;}
    return d;}
int main()
{
    cin>>n>>k; a.resize(n+1);
    vector<bool>b(n+1);
    for(int i=2; i<=n; i++){
        long long x,y; cin>>x>>y;
        a[x].kim.push_back(i);
        a[i].fon=y;}
    long long s=1,t=10e14,koz;
    while(s!=t){
        l=0; koz=(s+t)/2;
        int r=tav(1,koz);
        if(l<=k)t=koz;
        else s=koz+1;}
    cout<<t;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms316 KiB
2Accepted0/09ms564 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted3/32ms316 KiB
9Accepted3/34ms372 KiB
10Accepted3/37ms316 KiB
11Accepted3/38ms624 KiB
12Accepted3/310ms640 KiB
13Accepted4/412ms688 KiB
14Accepted4/414ms732 KiB
15Accepted4/416ms876 KiB
16Wrong answer0/417ms952 KiB
17Accepted4/419ms820 KiB