#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[100005], h[100005], s[100005], a[100005];
void rd() {
  scanf("%d", &n);
  h[1] = 1;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &f[i]);
    h[i] = h[f[i]] + 1;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
}
int main() {
  rd();
  for (int i = 1; i <= n; i++) {
    if (s[i] != -1 && s[i] < s[f[f[i]]] && i != 1) {
      cout << -1;
      return 0;
    }
    if ((h[i] & 1) && s[i] == -1) {
      cout << -1;
      return 0;
    }
    if ((!(h[i] & 1)) && s[i] != -1) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 2; i <= n; i++)
    if (h[i] & 1) {
      if (s[f[i]] == -1)
        s[f[i]] = s[i];
      else
        s[f[i]] = min(s[f[i]], s[i]);
    }
  for (int i = 2; i <= n; i++)
    if (s[i] == -1) s[i] = s[f[i]];
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = s[i] - s[f[i]];
    ans += a[i];
  }
  cout << ans;
  return 0;
}
