#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 5;
vector<int> par;
vector<int> s;
vector<int> adj[nax];
vector<int> a;
vector<bool> vis;
bool flag = true;
bool check(vector<int>& v, long long int prev_sum) {
  sort(v.begin(), v.end());
  if (v[0] >= prev_sum)
    return true;
  else
    return false;
}
void dfs(int u, long long int prev_sum) {
  vector<int> child;
  vis[u] = true;
  for (int v : adj[u]) {
    if (!vis[v]) {
      if (s[u] == -1) {
        child.push_back(s[v]);
      }
      dfs(v, s[u]);
    }
  }
  if (s[u] == -1) {
    if (child.size() == 0)
      s[u] = prev_sum;
    else {
      if (check(child, prev_sum)) {
        s[u] = child[0];
      } else
        flag = false;
    }
  }
}
void dfs2(int u, long long int& sum, long long int prev_sum) {
  sum += s[u] - prev_sum;
  vis[u] = true;
  for (int v : adj[u]) {
    if (!vis[v]) {
      dfs2(v, sum, s[u]);
    }
  }
}
long long int solve(int n) {
  vis = vector<bool>(n + 1, false);
  dfs(1, 0);
  a = vector<int>(n + 1);
  if (!flag) return -1;
  vis = vector<bool>(n + 1, false);
  long long int sum = 0;
  dfs2(1, sum, 0);
  return sum;
}
int main() {
  int n;
  cin >> n;
  par = vector<int>(n + 1);
  s = vector<int>(n + 1);
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    adj[i].push_back(p);
    adj[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  cout << solve(n) << "\n";
}
