#include <bits/stdc++.h>
using namespace std;
long long int pr[500100], su[500100];
long long int ans;
vector<int> v[500100];
void soll(int node, int p, int nd, int cnt) {
  cnt %= 2;
  if (cnt == 1 && node != 1) {
    if (su[node] - nd < 0) {
      cout << -1;
      exit(0);
    }
  }
  if (cnt == 0 && v[node].size() == 1) {
    su[node] = su[p];
    return;
  }
  long long int minn = 1e18;
  for (auto nd : v[node]) {
    if (nd == p) continue;
    minn = min(minn, su[nd]);
  }
  if (cnt == 0) su[node] = minn;
  for (auto nd : v[node]) {
    if (nd == p) continue;
    soll(nd, node, su[p], cnt + 1);
  }
}
void sol(int node, int p) {
  for (auto nd : v[node]) {
    if (nd == p) continue;
    ans += su[nd] - su[node];
    if (su[nd] - su[node] < 0) {
      cout << -1;
      exit(0);
    }
    sol(nd, node);
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    v[x].push_back(i);
    v[i].push_back(x);
  }
  for (int i = 1; i <= n; i++) cin >> su[i];
  soll(1, 0, 0, 1);
  sol(1, 0);
  ans += su[1];
  cout << ans;
  return 0;
}
