20262022-12-15 10:37:58BenceTevefarmcpp11Partially correct 48/50100ms12692 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

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

struct adat
{
    bool jo,lat;
    int teve;
    vector <int> sz;
};
queue <int> s;
vector <adat> x;
int n,i,a,db;

long long rekurzio (int pont)
{
    long long ss=0;
    if(!x[pont].sz.empty())
    {
        for(auto &e:x[pont].sz)
        {
            ss+=rekurzio(e);
        }
        if(x[pont].teve>=ss)
        {
            x[pont].jo=1;
            return x[pont].teve;
        }else{
            return ss;
        }
    }else{
        x[pont].jo=1;
        return x[pont].teve;
    }
}

void rekur (int pont)
{
    if(x[pont].jo==1)
    {
        x[pont].lat=1;
        ++db;
    }else{
        for(auto &e:x[pont].sz)
            rekur(e);
    }
}

int main()
{
    cin>>n;
    x.resize(n+1);
    for(i=1; i<=n; ++i)
    {
        cin>>x[i].teve;
    }
    for(i=2; i<=n; ++i)
    {
        cin>>a;
        x[a].sz.push_back(i);
    }

    cout<<rekurzio(1)<<'\n';
    rekur(1);
    cout<<db<<'\n';
    for(i=2; i<=n; ++i)
    {
        if(x[i].lat)
            cout<<i<<' ';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base48/50
1Accepted0/03ms1684 KiB
2Accepted0/03ms2024 KiB
3Partially correct2/42ms2052 KiB
4Accepted4/42ms2304 KiB
5Accepted4/42ms2516 KiB
6Accepted4/43ms2876 KiB
7Accepted4/441ms7532 KiB
8Accepted6/654ms8524 KiB
9Accepted6/659ms9524 KiB
10Accepted6/667ms10672 KiB
11Accepted6/690ms11576 KiB
12Accepted6/6100ms12692 KiB