#include <bits/stdc++.h>
using namespace std;
vector<int> childs[100000 + 1];
long long s[100000 + 1];
int p[100000 + 1];
long long a[100000 + 1];
bool flag = false;
void fill(int v, long long prevsum) {
  if (s[v] != -1) {
    a[v] = s[v] - prevsum;
    if (a[v] < 0) flag = true;
    for (int i = 0; i < childs[v].size(); ++i) {
      fill(childs[v][i], s[v]);
    }
  } else {
    long long mi = 1000000001;
    for (int i = 0; i < childs[v].size(); ++i) {
      mi = min(mi, s[childs[v][i]]);
    }
    if (mi == 1000000001) mi = prevsum;
    a[v] = mi - prevsum;
    if (a[v] < 0) flag = true;
    for (int i = 0; i < childs[v].size(); ++i) {
      fill(childs[v][i], mi);
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    childs[i].clear();
  }
  for (int i = 2; i < n + 1; ++i) {
    cin >> p[i];
    childs[p[i]].push_back(i);
  }
  for (int i = 1; i < n + 1; ++i) {
    cin >> s[i];
  }
  fill(1, 0);
  if (flag)
    cout << -1 << endl;
  else {
    long long sum = 0;
    for (int i = 1; i < n + 1; ++i) {
      sum += a[i];
    }
    cout << sum << endl;
  }
}
