#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> children;
vector<long long> L[2];
void dfs( int u, const vector<long long>& T ){
L[0][u] = 0;
L[1][u] = T[u];
for(int v : children[u]){
dfs( v, T);
L[0][u] += max( L[0][v], L[1][v] );
}8
5 5 7 1 2 3 2 4
1
1
2
2
2
3
3
}
int main(){
int n;
cin >> n;
vector<long long> T(n);
for(int i=0; i<n; i++){
cin >> T[i];
}
children.resize(n);
for(int i=1; i<n; i++){
int parent;
cin >> parent;
children[parent - 1].push_back(i);
}
L[0].assign(n, 0);
L[1].assign(n, 0);
dfs( 0, T );
long long max_sum = max(L[0][0], L[1][0]);
cout << max_sum;
}
open /var/local/lib/isolate/416/box/a.out: no such file or directory
main.cpp: In function 'void dfs(int, const std::vector<long long int>&)':
main.cpp:16:7: error: expected ';' before numeric constant
16 | }8
| ^
| ;
17 | 5 5 7 1 2 3 2 4
| ~