#include <bits/stdc++.h>
using namespace std;
long long int const N = 200005;
long long int pr[N + 20], sum[N + 20];
vector<long long int> adj[N + 20];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int x, n;
  cin >> n;
  for (long long int i = 2; i <= n; i++) {
    cin >> pr[i];
  }
  cin >> sum[1];
  for (long long int i = 2; i <= n; i++) {
    cin >> sum[i];
    if (sum[i] != -1) {
      if (sum[pr[i]] == -1 || sum[pr[i]] > sum[i]) sum[pr[i]] = sum[i];
    }
  }
  for (long long int i = 2; i <= n; i++) {
    if (sum[i] == -1) {
      sum[i] = sum[pr[i]];
    }
  }
  long long int ss = sum[1];
  for (long long int i = 2; i <= n; i++) {
    if (sum[i] < sum[pr[i]]) {
      cout << -1 << endl;
      return 0;
    }
    ss += (sum[i] - sum[pr[i]]);
  }
  cout << ss << endl;
  return 0;
}
