45502023-03-29 14:49:02AblablablaTevefarmcpp17Wrong answer 19/5093ms12288 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, string> pis;

int n;
vector<int> teve;
vector<vector<int>> graf;
vector<bool> jelolt;

int vizsgal(int helyzet){
    int osszeg = 0;
    for(int kov : graf[helyzet]){
        osszeg += vizsgal(kov);
    }

    if(osszeg < teve[helyzet]){
        jelolt[helyzet] = true;
        osszeg = teve[helyzet];
    }

    return osszeg;
}

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

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

    for(int i = 0; i < n - 1; i++){
        int a;
        cin >> a;
        graf[a - 1].push_back(i + 1);
    }
/*
    for(int i = 0; i < n; i++){
        cout << i << ": ";
        for(int x : graf[i]){
            cout << x << " ";
        }

        cout << "\n";
    }
*/
    int valasz = vizsgal(0);
    cout << valasz << "\n";
}
SubtaskSumTestVerdictTimeMemory
base19/50
1Wrong answer0/03ms1812 KiB
2Wrong answer0/03ms2228 KiB
3Partially correct2/43ms2660 KiB
4Partially correct2/43ms2536 KiB
5Partially correct2/43ms2676 KiB
6Partially correct2/43ms2788 KiB
7Partially correct2/439ms7016 KiB
8Partially correct3/646ms8268 KiB
9Partially correct3/654ms9264 KiB
10Partially correct3/661ms10168 KiB
11Wrong answer0/685ms11392 KiB
12Wrong answer0/693ms12288 KiB