#include <bits/stdc++.h>
const long long INF = 1e24;
const long long N = 2e6 + 77;
const long long MOD = 1e9 + 7;
using namespace std;
vector<long long> prime, g[N];
long long n, m, k, s[N], a[N];
void dfs(long long node, long long parent) {
  if (s[node] >= 0) {
    a[node] = s[node] - s[parent];
    for (long long i = 0; i < g[node].size(); i++) {
      long long y = g[node][i];
      if (y != parent && g[y].size() == 1) {
        if (s[y] != -1) {
          a[y] = s[y] - s[node];
        }
      }
      if (y != parent && g[y].size() > 1) dfs(y, node);
    }
  } else {
    long long x = INF;
    for (long long i = 0; i < g[node].size(); i++) {
      long long y = g[node][i];
      if (y != parent) {
        x = min(x, s[y] - s[parent]);
      }
    }
    if (x != INF) {
      a[node] = x;
      s[node] = a[node] + s[parent];
      for (long long i = 0; i < g[node].size(); i++) {
        long long y = g[node][i];
        if (y != parent && g[y].size() == 1) {
          if (s[y] != -1) {
            a[y] = s[y] - s[node];
          }
        }
        if (y != parent && g[y].size() > 1) dfs(y, node);
      }
    }
  }
}
long long POWER(long long base, long long expo) {
  long long ret = 1;
  while (expo) {
    if (expo & 1) ret = ret * base;
    expo >>= 1;
    base = base * base;
  }
  return ret;
}
int main() {
  long long test_case = 1;
  while (test_case--) {
    cin >> n;
    for (long long i = 2; i <= n; i++) {
      long long p;
      cin >> p;
      g[i].push_back(p);
      g[p].push_back(i);
    }
    for (long long i = 1; i <= n; i++) cin >> s[i];
    dfs(1LL, 0LL);
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
      ans += a[i];
      if (a[i] < 0) {
        cout << -1;
        return 0;
      }
    }
    cout << ans;
  }
  return 0;
}
