func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFLL = 1e18;   const int MOD = 1e9 + 7;   const int MAXN = 2e5 + 5;   vector<int> G[MAXN];   int n;   long long s[MAXN];   long long a[MAXN];   void dfs(int v, int p) {     if (s[v] == -1) {       long long aux = INF;       for (auto u : G[v])         if (u != p) {           aux = min(aux, s[u]);         }       if (aux == -1 || aux - s[p] < 0) {         a[v] = -1;         return;       }       if (aux == INF) {         a[v] = 0;         return;       }       a[v] = aux - s[p];       s[v] = a[v] + s[p];     } else {       if (p == v)         a[v] = s[v];       else         a[v] = s[v] - s[p];     }     for (auto u : G[v])       if (u != p) dfs(u, v);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x;       scanf( %d , &x);       x--;       G[x].push_back(i);       G[i].push_back(x);     }     for (int i = 0; i < n; i++) scanf( %lld , &s[i]);     dfs(0, 0);     long long ans = 0;     for (int i = 0; i < n; i++) {       if (a[i] < 0) {         printf( -1 n );         return 0;       }       ans += a[i];     }     printf( %lld n , ans);     return 0;   }   