#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n;
vector<int> g[N];
long long s[N], a[N], pr[N];
void dfs(int v, int p, int deep) {
  if (s[v] == -1 && deep % 2 != 0) {
    cout << -1;
    exit(0);
  }
  if (deep % 2 == 0) {
    long long mn = 1e15;
    if (g[v].size() == 0) {
      a[v] = 0;
      return;
    }
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i];
      mn = min(mn, s[to] - s[p]);
    }
    a[v] = mn;
    s[v] = s[p] + a[v];
  } else {
    a[v] = s[v] - s[p];
  }
  if (a[v] < 0) {
    cout << -1;
    exit(0);
  }
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    dfs(to, v, deep + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    pr[i] = x;
    g[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    a[i] = -1;
    cin >> s[i];
  }
  dfs(1, 0, 1);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
  }
  cout << sum;
}
