8142022-01-16 19:54:25Halasz EszterTársaság (50)cpp11Wrong answer 7/508ms3448 KiB
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long
using namespace std;

//ifstream cin("tarsasag.in");
//ofstream cout("tarsasag.out");

struct adat
{
    ll kezd,veg,tav;
};
vector< adat >x;

struct adat2
{
    ll veg,tav;
};
vector<adat2>y;

ll n,k,i,a,b,maxi=-1;
ll has(adat a, adat b)
{
    if(a.tav>b.tav) return 1;
    else return 0;
}

void mely(ll csp, ll t)
{
    if(y[csp].veg==0) y[csp].tav=max(y[csp].tav,t);
    else 
    {
        if(y[csp].veg!=0)  mely(y[csp].veg,t+y[csp].tav);
    }
}
int main()
{
    cin>>n>>k;
    x.resize(n+1);
    for(i=1;i<n;++i)
    {
        cin>>a>>b;
        x[i]={i+1,a,b};
    }

    sort(x.begin()+1,x.end(),has);

    //for(i=1;i<=n;++i) cout<<x[i].kezd<<" "<<x[i].veg<<" "<<x[i].tav<<"\n";

    y.resize(n+1);
    for(i=k+1;i<=n;++i)
        y[x[i].kezd]={x[i].veg,x[i].tav};
    

    //for(i=1;i<=n;++i)
     //cout<<i<<" "<<y[i].veg<<" "<<y[i].tav<<"\n";

    for(i=1;i<=n;++i)
    {
        if(y[i].veg!=0) mely(i,0);
    }

    for(i=1;i<=n;++i) if(y[i].tav>maxi) maxi=y[i].tav;
    cout<<maxi;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/02ms1804 KiB
2Wrong answer0/08ms2280 KiB
3Wrong answer0/31ms1960 KiB
4Wrong answer0/31ms1964 KiB
5Accepted3/31ms1976 KiB
6Wrong answer0/32ms1980 KiB
7Wrong answer0/32ms2000 KiB
8Wrong answer0/32ms2024 KiB
9Wrong answer0/33ms2080 KiB
10Wrong answer0/34ms2276 KiB
11Wrong answer0/36ms2344 KiB
12Wrong answer0/34ms2552 KiB
13Wrong answer0/48ms2520 KiB
14Wrong answer0/46ms2620 KiB
15Wrong answer0/47ms2864 KiB
16Accepted4/48ms3192 KiB
17Wrong answer0/48ms3448 KiB