#include <bits/stdc++.h>
using namespace std;
const long long mxn = 2e5 + 1;
vector<long long> tree[mxn];
long long flag = 1;
long long arr[mxn], depth[mxn], mn[mxn], val[mxn];
long long dfs(long long u, long long d) {
  depth[u] = d;
  long long himj = arr[u];
  if (depth[u] % 2 and arr[u] == -1) {
    flag = 0;
    return 1e16;
  }
  if (depth[u] % 2 == 0 and arr[u] != -1) {
    flag = 0;
    return 0;
  }
  if (himj == -1) himj = 1e16;
  for (auto v : tree[u]) {
    himj = min(himj, dfs(v, d + 1));
  }
  mn[u] = himj;
  if (arr[u] != -1 and mn[u] < arr[u]) {
    flag = 0;
    return 1e16;
  }
  return himj;
}
void solve(long long u, long long sum) {
  if (u == 1) {
    val[u] = arr[u];
  } else if (mn[u] < sum) {
    flag = 0;
    return;
  } else if (mn[u] == 1e16)
    val[u] = 0;
  else
    val[u] = mn[u] - sum;
  for (auto v : tree[u]) {
    solve(v, sum + val[u]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    long long n, i;
    cin >> n;
    for (i = 1; i < n; i++) {
      long long p;
      cin >> p;
      tree[p].push_back(i + 1);
    }
    for (i = 1; i < n + 1; i++) cin >> arr[i];
    dfs(1, 1);
    if (flag == 0) {
      cout << -1;
      return 0;
    }
    solve(1, 0);
    long long ans = 0;
    if (flag == 0) {
      cout << -1;
      return 0;
    }
    for (i = 1; i < n + 1; i++) {
      ans += val[i];
    }
    cout << ans;
  }
  return 0;
}
