#include <bits/stdc++.h>
using namespace std;
int n;
long long ans = 0LL;
long long s[100077];
long long a[100077];
vector<int> b[100077];
bool ok = true;
void work(int l, int r) {
  if (a[l] < 0) {
    if (b[l].size() == 0)
      a[l] = 0;
    else {
      long long mini = s[b[l][0]];
      for (int i = 0; i < b[l].size(); i++) {
        mini = min(mini, s[b[l][i]]);
      }
      long long dif = mini - s[r];
      s[l] = s[r] + dif;
      a[l] = dif;
      for (int i = 0; i < b[l].size(); i++) {
        int to = b[l][i];
        a[to] = s[to] - s[l];
      }
    }
  }
  for (int i = 0; i < b[l].size(); i++) {
    work(b[l][i], l);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    p--;
    b[p].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    a[i] = -1;
  }
  a[0] = s[0];
  work(0, -1);
  for (int i = 0; i < n; i++) {
    ok &= a[i] >= 0LL;
    ans += a[i];
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
