#include <bits/stdc++.h>
using namespace std;
long long n, p[100005], sum[100005], t, ans, mn;
queue<long long> q;
vector<long long> v[100005];
int main() {
  scanf("%lld", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%lld", &p[i]);
    v[p[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &sum[i]);
  }
  q.push(1);
  while (q.size()) {
    t = q.front();
    q.pop();
    if (sum[t] == -1) {
      if (!v[t].size()) {
        goto skip;
      }
      mn = 2147483640;
      for (int i = 0; i < v[t].size(); i++) {
        mn = min(mn, sum[v[t][i]]);
      }
      if (mn < sum[p[t]]) {
        printf("-1\n");
        return 0;
      }
      sum[t] = mn;
      ans += (sum[t] - sum[p[t]]);
    skip:;
    } else {
      if (sum[t] < sum[p[t]]) {
        printf("-1\n");
        return 0;
      }
      ans += (sum[t] - sum[p[t]]);
    }
    for (int i = 0; i < v[t].size(); i++) {
      q.push(v[t][i]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
