#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 2;
long long s[N], s12[N];
set<int> s1[N];
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    s1[p].insert(i);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  long long sum = s[1];
  queue<int> file;
  file.push(1);
  while (!file.empty()) {
    int u = file.front();
    long long sum1 = s[u];
    file.pop();
    if (s[u] == -1) {
      if (s1[u].empty())
        ;
      else {
        long long minn = 1e10;
        for (set<int>::iterator it = s1[u].begin(); it != s1[u].end(); it++) {
          file.push(*it);
          if (s[*it] < minn) minn = s[*it];
        }
        if (s12[u] <= minn) {
          sum += minn - s12[u];
          for (set<int>::iterator it = s1[u].begin(); it != s1[u].end(); it++)
            sum += s[*it] - minn;
        } else {
          cout << "-1";
          return 0;
        }
      }
    } else {
      for (set<int>::iterator it = s1[u].begin(); it != s1[u].end(); it++) {
        file.push(*it);
        s12[*it] = s[u];
      }
    }
  }
  cout << sum;
}
