#include <bits/stdc++.h>   using namespace std;   const long long N = 200001;   std::vector<long long> g[N];   long long s[N];   long long h[N];   long long a[N] = {0};   bool visited[N] = {false};   void dfs1(long long n, long long parent, long long depth) {     h[n] = depth;     for (long long v : g[n]) {       if (v != parent) {         dfs1(v, n, depth + 1);       }     }   }   void dfs2(long long n, long long parent) {     if (h[n] % 2 == 0) {       for (long long v : g[n]) {         if (v != parent) {           a[n] = s[v] - s[parent];         }       }       for (long long v : g[n]) {         if (v != parent) {           a[n] = min(s[v] - s[parent], a[n]);         }       }       s[n] = a[n] + s[parent];     } else {       a[n] = s[n] - s[parent];     }     for (long long v : g[n]) {       if (v != parent) {         dfs2(v, n);       }     }   }   int main() {     long long n;     cin >> n;     for (long long i = 2; i <= n; i++) {       long long parent;       cin >> parent;       g[parent].push_back(i);       g[i].push_back(parent);     }     for (long long i = 1; i <= n; i++) {       cin >> s[i];     }     dfs1(1, -1, 1);     a[1] = s[1];     dfs2(1, n + 1);     long long sum = 0;     for (long long i = 1; i <= n; i++) {       if (a[i] < 0) {         cout <<  -1  << endl;         return 0;       }       sum += a[i];     }     cout << sum << endl;   }   