94002024-02-21 12:48:08csaron71Tevefarmcpp17Wrong answer 25/5096ms14444 KiB
#include <bits/stdc++.h>
using namespace std;

vector<long long> ertek;
vector<long long> apa;
vector<vector<long long> > gyerekek;

long long kereses(long long x) {
	if (gyerekek[x].size()>0) {
		long long epp=ertek[x];
		long long masik=0;
		for (long long sz : gyerekek[x]) {
			masik+=kereses(sz);
		}
		return max(epp, masik);
	}
	else {
		return ertek[x];
	}
	
}

int main() {
	long long n;
	cin >> n;
	ertek.resize(n);
	for (long long i=0; i<n; i++) {
		cin >> ertek[i];
	}
	apa.resize(n);
	apa[0]=0;
	gyerekek.assign(n, vector<long long>());
	for (long long i=1; i<n; i++) {
		cin >> apa[i];
		apa[i]--;
		gyerekek[apa[i]].push_back(i);
	}

	cout << kereses(0);
}
SubtaskSumTestVerdictTimeMemory
base25/50
1Wrong answer0/03ms1812 KiB
2Wrong answer0/03ms2240 KiB
3Partially correct2/43ms2268 KiB
4Partially correct2/43ms2516 KiB
5Partially correct2/43ms2800 KiB
6Partially correct2/43ms3052 KiB
7Partially correct2/439ms8460 KiB
8Partially correct3/646ms9628 KiB
9Partially correct3/654ms10668 KiB
10Partially correct3/664ms12096 KiB
11Partially correct3/687ms13140 KiB
12Partially correct3/696ms14444 KiB