69452023-12-21 07:50:09Huni136Tevefarmcpp17Wrong answer 0/504ms8464 KiB
#include <iostream>
#include <vector>
#include <set>
#include <bitset>
#include <fstream>
using namespace std;

ifstream fin("be.txt");

vector<int> vc[100001];
int n;
int *ertekek;
int *megoldas;
set<int> valami;
//bitset<100001> lehetnek(false);
//set<int> lehetnek;

//int *t;

int megold(int nod)
{
    int s=0;
    for(auto it: vc[nod])
    {
        s=s+megold(it);
    }
    megoldas[nod]=max(s,ertekek[nod]);
    return max(s,ertekek[nod]);
}

void eredmeny(int nod)
{
    if(ertekek[nod]==megoldas[nod])
    {
        valami.insert(nod);
    }
    else
    {
        for(auto it: vc[nod])
        {
            eredmeny(it);
        }
    }
}


int main()
{
    fin>>n;
    ertekek=new int[n+1];
    megoldas=new int[n+1];
    int x;
    
    for(int i=1;i<=n;i++)
    {
        fin>>x;

       // valami.insert(i);
        ertekek[i]=x;
        megoldas[i]=x;
    }

    for(int i=2;i<=n;i++)
    {
        fin>>x;
        vc[x].emplace_back(i);
    }

    megold(1);
    eredmeny(1);
    // set<int> ered;
    cout<<megoldas[1]<<endl;

    // for(int i=1;i<=n;i++)
    // {
    //     if(megoldas[i]==ertekek[i])
    //     {
    //         ered.insert(i);
    //     }
    // }

    cout<<valami.size()<<endl;
    for(auto it:valami)
    {
        cout<<it<<" ";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/04ms6516 KiB
2Wrong answer0/04ms6856 KiB
3Wrong answer0/44ms7048 KiB
4Wrong answer0/44ms7380 KiB
5Wrong answer0/44ms7476 KiB
6Wrong answer0/44ms7436 KiB
7Wrong answer0/44ms7752 KiB
8Wrong answer0/64ms7900 KiB
9Wrong answer0/64ms7856 KiB
10Wrong answer0/64ms8128 KiB
11Wrong answer0/64ms8464 KiB
12Wrong answer0/64ms8424 KiB