45512023-03-29 14:51:06AblablablaTevefarmcpp17Wrong answer 25/5096ms12056 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll vizsgal(int helyzet){
    ll 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";
    }
*/
    ll valasz = vizsgal(0);
    cout << valasz << "\n";
}
SubtaskSumTestVerdictTimeMemory
base25/50
1Wrong answer0/03ms1808 KiB
2Wrong answer0/03ms2172 KiB
3Partially correct2/43ms2352 KiB
4Partially correct2/43ms2500 KiB
5Partially correct2/43ms2728 KiB
6Partially correct2/43ms3032 KiB
7Partially correct2/439ms7152 KiB
8Partially correct3/646ms8156 KiB
9Partially correct3/652ms9192 KiB
10Partially correct3/661ms9960 KiB
11Partially correct3/685ms10884 KiB
12Partially correct3/696ms12056 KiB