#include <bits/stdc++.h>
using namespace std;
int n, p, h[100005], par[100005];
long long ans, s[100005];
vector<int> a[100005];
int main() {
  cin >> n;
  h[1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> p;
    par[i] = p;
    h[i] = h[p] + 1;
    a[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  ans = 0;
  for (int u = 1; u <= n; u++) {
    if (h[u] % 2 == 0) {
      s[u] = 1000000000;
      for (int v : a[u]) s[u] = min(s[u], s[v]);
      if (s[u] == 1000000000) s[u] = s[par[u]];
      if (s[u] < s[par[u]]) return cout << -1, 0;
    }
    ans += s[u] - s[par[u]];
  }
  cout << ans;
  return 0;
}
