#include <bits/stdc++.h>
using namespace std;
int n;
string s;
vector<vector<int>> G;
vector<int> Cost, RealCost, Par;
void dfs(int v, int par, int h) {
  if (h) {
    int mi = 2e9;
    if ((long long)(G[v]).size() == 1) {
      mi = Cost[par];
    }
    for (auto u : G[v]) {
      if (u == par) {
        continue;
      }
      mi = min(Cost[u], mi);
    }
    if (mi < Cost[par]) {
      cout << -1;
      exit(0);
    } else {
      RealCost[v] = mi - Cost[par];
    }
    for (auto u : G[v]) {
      if (u == par) {
        continue;
      }
      dfs(u, v, h ^ 1);
    }
    return;
  } else {
    if (v == 0) {
      RealCost[v] = Cost[v];
      for (auto u : G[v]) {
        dfs(u, v, h ^ 1);
      }
      return;
    }
    RealCost[v] = Cost[v] - Cost[Par[par]] - RealCost[par];
    for (auto u : G[v]) {
      if (u == par) {
        continue;
      }
      dfs(u, v, h ^ 1);
    }
    return;
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  G.resize(n);
  Cost.resize(n);
  RealCost.resize(n);
  Par.resize(n);
  for (int i = 1; i < n; i++) {
    int v;
    cin >> v;
    v--;
    G[i].push_back(v);
    G[v].push_back(i);
    Par[i] = v;
  }
  for (int i = 0; i < n; i++) {
    cin >> Cost[i];
  }
  dfs(0, -1, 0);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += RealCost[i];
  }
  cout << ans;
}
