#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1], b[n + 1];
  for (int i = 2; i < n + 1; ++i) scanf("%d", &a[i]);
  scanf("%d", &b[1]);
  for (int i = 2; i < n + 1; ++i) {
    scanf("%d", &b[i]);
    if (b[i] != -1)
      if (b[a[i]] == -1 || b[a[i]] > b[i]) b[a[i]] = b[i];
  }
  for (int i = 2; i < n + 1; ++i) {
    if (b[i] == -1) b[i] = b[a[i]];
  }
  long long int sum = (long long int)b[1];
  for (int i = 2; i < n + 1; ++i) {
    if (b[i] < b[a[i]]) {
      printf("%d\n", -1);
      exit(0);
    } else
      sum += b[i] - b[a[i]];
  }
  printf("%lld\n", sum);
}
