#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
long long N = 1e5 + 10;
vector<long long> S(N);
vector<long long> adj[100010];
vector<long long> A(N);
vector<long long> MIN(N, INT_MAX);
bool f = true;
vector<long long> PAR(N);
void dfs(long long node, long long par, long long curr_sum, long long level) {
  if (S[node] != -1) {
    if (curr_sum > S[node]) {
      f = false;
      return;
    } else {
      A[node] = S[node] - curr_sum;
      curr_sum = S[node];
    }
  } else {
    long long z = MIN[node];
    if (z == INT_MAX) {
      A[node] = 0;
    } else {
      long long rem = z - curr_sum;
      if (rem < 0) {
        f = false;
        return;
      } else {
        A[node] = rem;
        curr_sum = z;
      }
    }
  }
  for (auto x : adj[node]) {
    if (x == par) continue;
    dfs(x, node, curr_sum, level + 1);
  }
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 2; i <= n; ++i) {
    long long p;
    cin >> p;
    PAR[i] = p;
    adj[i].push_back(p);
    adj[p].push_back(i);
  }
  for (long long i = 1; i <= n; ++i) cin >> S[i];
  for (long long i = 2; i <= n; ++i) {
    MIN[PAR[i]] = min(MIN[PAR[i]], S[i]);
  }
  long long ans = 0;
  dfs(1, -1, 0, 1);
  if (!f) {
    cout << -1 << endl;
  } else {
    for (long long i = 1; i <= n; ++i) {
      ans += A[i];
    }
    cout << ans << endl;
  }
}
int main() {
  init();
  long long t = 1;
  while (t--) {
    solve();
  }
}
