#include <bits/stdc++.h>
using namespace std;
long long int v[100007], last[100007], head[100007], deep[100007], a[100007],
    s[100007], ans, tot, fa[100007], t, n, p;
inline void read(long long int &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x *= f;
}
inline void build(long long int x, long long int y) {
  v[++tot] = y;
  last[tot] = head[x];
  head[x] = tot;
  deep[y] = deep[x] + 1;
}
inline void dfs(long long int x) {
  long long int m = 0x7fffffff;
  for (long long int i = head[x]; i; i = last[i]) {
    if (s[x] == -1) m = min(m, s[v[i]]);
    dfs(v[i]);
  }
  if (s[x] == -1) {
    if (m == 0x7fffffff)
      a[x] = 0;
    else {
      a[x] = m - s[fa[x]];
      if (a[x] < 0) t = 1;
    }
  }
}
inline void dfs2(long long int x) {
  for (long long int i = head[x]; i; i = last[i]) {
    if (s[v[i]] == -1) s[v[i]] = s[x] + a[v[i]];
    if (a[v[i]] == 0) a[v[i]] = s[v[i]] - s[x];
    dfs2(v[i]);
  }
}
int main() {
  read(n);
  for (long long int i = 2; i <= n; i++) {
    read(p);
    fa[i] = p;
    build(p, i);
  }
  for (long long int i = 1; i <= n; i++) cin >> s[i];
  dfs(1);
  if (t == 1)
    cout << "-1" << endl;
  else {
    dfs2(1);
    a[1] = s[1];
    for (long long int i = 1; i <= n; i++) ans += a[i];
    cout << ans << endl;
  }
}
