#include <bits/stdc++.h>
using namespace std;
vector<int> pr;
long long ans = 0;
void dfs(int v, vector<vector<int>> &g, vector<int> &s) {
  if (g[v].empty()) {
    if (s[v] == -1) {
      s[v] = s[pr[v]];
    }
  } else {
    if (s[v] == -1) {
      s[v] = s[g[v][0]];
      for (auto i : g[v]) {
        s[v] = min(s[v], s[i]);
        if (pr[v] != -1 && s[i] < s[pr[v]]) {
          cout << -1;
          exit(0);
        }
      }
      for (auto i : g[v]) dfs(i, g, s);
    } else {
      for (auto i : g[v]) {
        dfs(i, g, s);
      }
    }
  }
}
void dfs1(int v, vector<vector<int>> &g, vector<int> &s) {
  for (auto i : g[v]) {
    if (pr[i] != -1) ans += s[i] - s[pr[i]];
    dfs1(i, g, s);
  }
}
void solve() {
  int n;
  cin >> n;
  vector<int> s(n);
  pr.resize(n, -1);
  vector<vector<int>> g(n);
  for (int i = 1; i < n; i++) {
    int v;
    cin >> v;
    v--;
    g[v].push_back(i);
    pr[i] = v;
  }
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<bool> used(n);
  dfs(0, g, s);
  dfs1(0, g, s);
  cout << ans + s[0];
}
int main() {
  solve();
  return 0;
}
