#include <bits/stdc++.h>
using namespace std;
inline int mul(int a, int b) { return int(a * 1ll * b % 1000000007); }
inline int norm(int a) {
  if (a >= 1000000007) a -= 1000000007;
  if (a < 0) a += 1000000007;
  return a;
}
inline int binPow(int a, int k) {
  int ans = 1;
  while (k > 0) {
    if (k & 1) ans = mul(ans, a);
    a = mul(a, a);
    k >>= 1;
  }
  return ans;
}
inline int subtract(int a, int b) { return norm(a - b); }
inline int sum(int a, int b) { return int((a + b) % 1000000007); }
inline int inv(int a) { return binPow(a, 1000000007 - 2); }
vector<int> p;
vector<long long> s;
vector<long long> h;
vector<long long> a;
vector<vector<int>> t;
long long res = 0;
void dfs2(int v, int p = -1) {
  if (s[v] == -1) {
    long long val = -1;
    for (int i = 0; i < t[v].size(); i++) {
      if (t[v][i] != p) {
        if (val == -1) {
          val = s[t[v][i]];
        } else {
          val = min(val, s[t[v][i]]);
        }
      }
    }
    if (val == -1) val = s[p];
    s[v] = val;
    a[v] = s[v] - s[p];
  }
  if (s[v] != -1) {
    if (p != -1) a[v] = s[v] - s[p];
    for (int i = 0; i < t[v].size(); i++) {
      if (t[v][i] != p) {
        dfs2(t[v][i], v);
        if (res == -1) return;
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  p.resize(n);
  s.resize(n);
  t.resize(n);
  a.resize(n);
  h.resize(n, -1);
  h[0] = 1;
  p[0] = 0;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    x--;
    p[i] = x;
    t[x].push_back(i);
    t[i].push_back(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  a[0] = s[0];
  dfs2(0);
  for (int i = 0; i < n; i++) {
    if (a[i] < 0) {
      cout << -1;
      return 0;
    }
    res += a[i];
  }
  cout << res;
  return 0;
}
