#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> g(200000);
long long a[200000];
long long s[200000];
void dfs(long long v, bool h = true, long long p = -1) {
  if (s[v] != -1) {
    if (!h) {
      cout << -1;
      exit(0);
    }
    for (auto i : g[v]) {
      dfs(i, !h, v);
    }
    return;
  }
  long long pz = s[p];
  long long mi = (long long)1e18;
  for (auto i : g[v]) {
    mi = min(mi, s[i]);
  }
  if (mi == (long long)1e18) {
    mi = pz;
  }
  if (mi < pz) {
    cout << -1;
    exit(0);
  }
  s[v] = mi;
  for (auto i : g[v]) {
    dfs(i, !h, v);
  }
}
void df(int v, int p = -1) {
  if (v != 0) a[v] = s[v] - s[p];
  for (auto i : g[v]) {
    df(i, v);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long p;
    cin >> p;
    g[p - 1].emplace_back(i + 1);
  }
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  dfs(0);
  df(0);
  a[0] = s[0];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans;
}
