45422023-03-29 13:51:11AblablablaTevefarmcpp17Wrong answer 0/50119ms12080 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 << " " << osszeg << "\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
base0/50
1Wrong answer0/03ms1812 KiB
2Wrong answer0/03ms2224 KiB
3Wrong answer0/42ms2136 KiB
4Wrong answer0/43ms2268 KiB
5Wrong answer0/43ms2496 KiB
6Wrong answer0/43ms2864 KiB
7Wrong answer0/448ms6928 KiB
8Wrong answer0/659ms8080 KiB
9Wrong answer0/670ms9272 KiB
10Wrong answer0/679ms10184 KiB
11Wrong answer0/6107ms11160 KiB
12Wrong answer0/6119ms12080 KiB