func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 110000;   vector<int> adj[N];   long long p[N], s[N];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 2; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i <= n; i++) {       if (~s[i]) {         int j = p[p[i]];         int k = p[i];         if (s[i] < s[j]) return puts( -1 ), 0;         adj[k].push_back(s[i] - s[j]);       }     }     long long dap = s[1];     for (int i = 1; i <= n; i++) {       if (!adj[i].empty()) {         sort(adj[i].begin(), adj[i].end());         dap += adj[i][0];         for (int x : adj[i]) dap += (x - adj[i][0]);       }     }     cout << dap << endl;     return 0;   }   