#include <bits/stdc++.h>
using namespace std;
const bool debug = 0;
int n;
int p[100005], a[100005], s[100005];
vector<int> c[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  p[0] = -1;
  for (int i = (1); i < (n); ++i) {
    cin >> p[i];
    p[i]--;
    c[p[i]].push_back(i);
  }
  stack<int> odds;
  stack<int> evens;
  for (int i = (0); i < (n); ++i) {
    a[i] = -1;
    cin >> s[i];
    if (s[i] == -1)
      evens.push(i);
    else
      odds.push(i);
  }
  long long ret = 0;
  while (!evens.empty()) {
    int tmp = evens.top();
    evens.pop();
    int ps = s[p[tmp]];
    int mch = -1;
    for (auto ch : c[tmp]) {
      if (s[ch] < ps) {
        cout << -1 << endl;
        exit(0);
      } else {
        if (mch == -1)
          mch = s[ch];
        else
          mch = min(mch, s[ch]);
      }
    }
    if (mch == -1) mch = ps;
    s[tmp] = mch;
    a[tmp] = mch - ps;
    ret += a[tmp];
    if (debug) cout << tmp << " " << a[tmp] << endl;
  }
  if (debug) cout << "end of even" << endl;
  while (!odds.empty()) {
    int tmp = odds.top();
    odds.pop();
    if (p[tmp] == -1)
      a[tmp] = s[tmp];
    else {
      a[tmp] = s[tmp] - s[p[tmp]];
    }
    if (a[tmp] < 0) {
      cout << -1 << endl;
      exit(0);
    }
    ret += a[tmp];
    if (debug) cout << tmp << " " << a[tmp] << endl;
  }
  cout << ret << endl;
  return 0;
}
