95252024-02-22 14:44:30Vkrisztian01Tevefarmcpp17Wrong answer 38/5093ms12876 KiB
#include <iostream>
#include<vector>

using namespace std;


int n,a,b;
vector<vector<int> > g;
vector<int>label;
vector<int>dp;
vector<bool>valasztom;
vector<int>ki;

void dfs(int node)
{
    int osszeg=0;
    for(auto to:g[node])
    {
        dfs(to);
        osszeg+=dp[to];
    }
    dp[node]=max(label[node],osszeg);
    if(label[node]>osszeg) valasztom[node]=true;
    else valasztom[node]=false;
}

void bejar(int node)
{
    if(valasztom[node])
    {
        ki.push_back(node);
        return;
    }
    for(auto to:g[node]) bejar(to);
}

int main()
{
    cin>>n;
    g.resize(n+1);
    dp.assign(n+1,0);
    valasztom.resize(n+1);
    label.resize(n+1);
    for(int i=1;i<=n;i++) cin>>label[i];
    for(int i=2;i<=n;i++)
    {
        cin>>a;
        g[a].push_back(i);
    }
    dfs(1);
    cout<<dp[1]<<endl;
    bejar(1);
    cout<<ki.size()<<endl;
    for(auto x:ki) cout<<x<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base38/50
1Accepted0/03ms1876 KiB
2Accepted0/03ms2304 KiB
3Accepted4/43ms2576 KiB
4Accepted4/43ms2632 KiB
5Accepted4/43ms2760 KiB
6Accepted4/43ms3104 KiB
7Accepted4/443ms8108 KiB
8Accepted6/650ms9220 KiB
9Accepted6/661ms10572 KiB
10Accepted6/674ms11592 KiB
11Wrong answer0/683ms11872 KiB
12Wrong answer0/693ms12876 KiB