#include <bits/stdc++.h>
using namespace std;
deque<int> divisors;
vector<int> primes, factors;
const long long mod = LLONG_MAX;
long long off;
void find_off(int x) {
  off = 1;
  while (off < x) off *= 2;
  return;
}
void find_divisors(int x) {
  divisors.clear();
  bool flag = 0;
  if ((int)sqrt(x) * (int)sqrt(x) == x) {
    flag = 1;
    divisors.push_back(sqrt(x));
  }
  for (int i = sqrt(x) - flag; i > 0; i--) {
    if (x % i == 0) {
      divisors.push_front(i);
      divisors.push_back(x / i);
    }
  }
  return;
}
void find_primes(long long x) {
  bool prime[x + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= x; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= x; i += p) prime[i] = false;
    }
  }
  for (int i = 2; i <= x; i++) {
    if (prime[i]) primes.push_back(i);
  }
  sort(primes.begin(), primes.end());
  return;
}
bool is_prime(long long x) {
  if (x == 2) return 1;
  for (int i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
void find_factors(long long x) {
  factors.clear();
  while (x % 2 == 0) {
    factors.push_back(2);
    x = x / 2;
  }
  for (int i = 3; i <= sqrt(x); i = i + 2) {
    while (x % i == 0) {
      factors.push_back(i);
      x = x / i;
    }
  }
  if (x > 2) factors.push_back(x);
  sort(factors.begin(), factors.end());
  return;
}
bool is_palindrome(string x) {
  bool qw = 1;
  for (int i = 0; i < x.size() / 2; i++) {
    if (x[i] != x[x.size() - 1 - i]) qw = 0;
  }
  return qw;
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / (gcd(x, y)); }
long long add(long long x, long long y) { return (x + y + mod) % mod; }
long long mul(long long x, long long y) { return (x * y + mod) % mod; }
long long pot(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  if (y % 2 == 0) {
    long long z = pot(x, y / 2);
    return mul(z, z);
  } else {
    long long z = pot(x, y / 2);
    return mul(mul(z, z), x);
  }
}
long long N;
long long par[200200];
vector<int> v[200200];
long long s[200200];
long long a[200200];
long long sol = 0;
void dfs(int x) {
  if (s[x] == -1) {
    if (v[x].size() != 0) {
      long long mini = 1e9;
      for (int i = 0; i < v[x].size(); i++) {
        mini = min(mini, s[v[x][i]]);
      }
      a[x] = mini - s[par[x]];
    } else
      a[x] = 0;
  } else {
    if (x != 1) {
      a[x] = s[x] - (s[par[par[x]]] + a[par[x]]);
    }
  }
  for (int i = 0; i < v[x].size(); i++) dfs(v[x][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 2; i <= N; i++) {
    cin >> par[i];
    v[par[i]].push_back(i);
  }
  for (int i = 1; i <= N; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= N; i++) a[i] = 1e9;
  a[1] = s[1];
  dfs(1);
  for (int i = 1; i <= N; i++) {
    sol += a[i];
    if (a[i] < 0) {
      cout << -1;
      return 0;
    }
  }
  cout << sol;
}
