45432023-03-29 13:56:48AblablablaTevefarmcpp17Wrong answer 19/5090ms12336 KiB
#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> teve;
vector<vector<int>> elsoVar;

int vizsgal(int helyzet){
    int osszeg = 0;

    for(int x : elsoVar[helyzet]){
        osszeg += vizsgal(x);
    }

    //cout << helyzet << " " << max(osszeg, teve[helyzet]) << "\n";

    return max(osszeg, teve[helyzet]);
}

int main()
{
    cin >> n;
    teve.assign(n, 0);
    elsoVar.assign(n, vector<int>(0, 0));

    for(int i = 0; i < n; i++){
        cin >> teve[i];
    }

    for(int i = 0; i < n - 1; i++){
        int a;
        cin >> a;
        elsoVar[a - 1].push_back(i + 1);
    }

    /*for(int i = 0; i < n; i++){
        for(int x : elsoVar[i]){
            cout << x << " ";
        }

        cout << "\n";
    }*/

    cout << max(vizsgal(0), teve[0]) << "\n";
}
SubtaskSumTestVerdictTimeMemory
base19/50
1Wrong answer0/03ms1808 KiB
2Wrong answer0/03ms2240 KiB
3Partially correct2/42ms2272 KiB
4Partially correct2/43ms2524 KiB
5Partially correct2/43ms2868 KiB
6Partially correct2/43ms3028 KiB
7Partially correct2/437ms7020 KiB
8Partially correct3/645ms8300 KiB
9Partially correct3/652ms9420 KiB
10Partially correct3/659ms10044 KiB
11Wrong answer0/681ms11216 KiB
12Wrong answer0/690ms12336 KiB