#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 123;
int n, p[MAXN], s[MAXN], a[MAXN];
vector<int> c[MAXN];
void inp();
void dfs(int);
int main() {
  inp();
  a[0] = s[0];
  dfs(0);
  for (int i = 0; i < n; i++)
    if (a[i] < 0) return cout << -1, 0;
  cout << accumulate(a, a + n, 0ll);
  return 0;
}
void inp() {
  cin >> n;
  p[0] = -1;
  for (int i = 1; i < n; i++) cin >> p[i], c[--p[i]].push_back(i);
  for (int i = 0; i < n; i++) cin >> s[i];
}
void dfs(int v) {
  if (c[v].empty()) return;
  if (~s[v])
    for (int u : c[v]) dfs(u);
  else {
    int kam = INT_MAX;
    for (int u : c[v]) kam = min(kam, s[u]);
    a[v] = kam - s[p[v]];
    s[v] = s[p[v]] + a[v];
    for (int u : c[v]) {
      a[u] = s[u] - s[v];
      dfs(u);
    }
  }
}
