#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> adj[100002];
long long parent[100002];
long long sum[100002];
long long akele[100002];
long long vis[100002] = {0};
long long ans;
void dfs1(long long s) {
  vis[s] = 1;
  long long mm = 1000000000000000007;
  for (long long i = 0; i < adj[s].size(); i++) {
    if (!vis[adj[s][i]]) {
      dfs1(adj[s][i]);
      mm = min(mm, sum[adj[s][i]]);
    }
  }
  if (sum[s] == -1) sum[s] = mm;
}
void dfs2(long long s) {
  if (ans == -1) {
    return;
  }
  vis[s] = 1;
  if ((s != 1) && (sum[s] != 1000000000000000007)) {
    long long val = sum[s] - sum[parent[s]];
    if (val < 0) {
      ans = -1;
    } else {
      ans += val;
    }
  }
  for (long long i = 0; i < adj[s].size(); i++) {
    if (!vis[adj[s][i]]) {
      dfs2(adj[s][i]);
    }
  }
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  long long temp;
  for (long long i = 2; i < n + 1; i++) {
    cin >> temp;
    adj[temp].push_back(i);
    parent[i] = temp;
  }
  for (long long i = 1; i < n + 1; i++) {
    cin >> sum[i];
  }
  akele[1] = sum[1];
  dfs1(1);
  for (long long i = 1; i < n + 1; i++) {
    vis[i] = 0;
  }
  ans = sum[1];
  dfs2(1);
  cout << ans << endl;
  return 0;
}
