func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long MAX = 10e5;   vector<long long> graph[MAX];   queue<long long> q;   bool visit[MAX];   long long a[MAX];   long long s[MAX];   long long parent[MAX];   int main() {     memset(visit, false, sizeof(visit));     long long nodes;     cin >> nodes;     for (auto i = 2; i <= nodes; ++i) {       long long tmp;       cin >> tmp;       parent[i] = tmp;       graph[i].push_back(tmp);       graph[tmp].push_back(i);     }     for (auto i = 1; i <= nodes; ++i) {       cin >> s[i];     }     a[1] = s[1];     q.push(1);     visit[1] = true;     while (!q.empty()) {       long long n = q.front();       q.pop();       if (n != 1) {         if (s[n] == -1) {           s[n] = s[parent[n]];           if (graph[n].size() > 1) {             long long mini = 10e9;             for (auto v : graph[n]) {               if (v == parent[n]) continue;               mini = min(mini, s[v]);             }             if (mini < s[n]) {               cout << -1;               return 0;             } else {               a[n] = mini - s[n];               s[n] = mini;             }           } else {             a[n] = 0;             s[n] = s[parent[n]];           }         } else {           a[n] = s[n] - s[parent[n]];         }       }       for (auto p : graph[n]) {         if (visit[p]) continue;         q.push(p);         visit[p] = true;       }     }     long long ans = 0;     for (auto i = 1; i <= nodes; i++) {       ans += a[i];     }     cout << ans;     return 0;   }   