#include <bits/stdc++.h>
using namespace std;
bool f(int u, int p, vector<vector<int>> &adj, vector<int> &s, long long &sum) {
  int au = -1;
  if (s[u] == -1) {
    int mins = INT_MAX;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      mins = min(mins, s[v]);
    }
    au = (mins == INT_MAX ? 0 : mins - s[p]);
    s[u] = s[p] + au;
  } else {
    au = max(au, s[u] - (p == -1 ? 0 : s[p]));
  }
  if (au < 0) {
    return false;
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (!f(v, u, adj, s, sum)) {
      return false;
    }
  }
  sum += au;
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<vector<int>> adj(n + 1);
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    adj[p].push_back(i);
  }
  vector<int> s(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  long long sum = 0;
  bool found = f(1, -1, adj, s, sum);
  cout << (found ? sum : -1);
  return 0;
}
