#include <bits/stdc++.h>
long long gcd(long long m, long long n) { return n == 0 ? m : gcd(n, m % n); }
long long lcm(long long m, long long n) { return m * n / gcd(m, n); }
long long pows(long long base, long long power, long long mod) {
  long long result = 1;
  while (power > 0) {
    if (power & 1) {
      result = result * base % mod;
    }
    power >>= 1;
    base = (base * base) % mod;
  }
  return result;
}
long long poww(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power & 1) {
      result = result * base;
    }
    power >>= 1;
    base = (base * base);
  }
  return result;
}
const long long inf = 1e17;
const int N = 3e5 + 10 + 10000;
const int M = 1e5 + 10;
const long long mod = 998244353;
using namespace std;
long long a[N], b[N];
long long n;
int main() {
  scanf("%lld", &n);
  for (long long i = 2; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
    if (i > 1 && b[i] != -1) {
      if (b[a[i]] == -1) {
        b[a[i]] = b[i];
      } else {
        b[a[i]] = min(b[a[i]], b[i]);
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (b[i] == -1) {
      b[i] = b[a[i]];
    }
  }
  long long ans = b[1];
  for (long long i = 2; i <= n; i++) {
    if (b[i] < b[a[i]]) {
      printf("%lld\n", (long long)-1);
      return 0;
    }
    ans += (b[i] - b[a[i]]);
  }
  printf("%lld\n", ans);
  return 0;
}
