#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
vector<long long> p[N];
long long s[N];
long long a[N];
void solve(long long start, long long tsum = 0) {
  if (s[start] != -1) {
    a[start] = s[start] - tsum;
    if (p[start].size()) {
      for (auto i : p[start]) solve(i, s[start]);
    }
  } else {
    if (p[start].size() == 0) {
      a[start] = 0;
      return;
    }
    long long val = INT_MAX;
    for (long long i : p[start]) {
      val = min(val, s[i]);
    }
    a[start] = val - tsum;
    for (auto i : p[start]) {
      solve(i, val);
    }
  }
}
int32_t main() {
  long long n;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x;
    cin >> x;
    x--;
    p[x].push_back(i);
  }
  for (long long i = 0; i < n; i++) cin >> s[i];
  solve(0);
  for (long long i = 0; i < n; i++) {
    if (a[i] < 0) {
      cout << -1;
      return 0;
    }
  }
  cout << accumulate(a, a + n, 0LL);
  return 0;
}
