#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 30;
const int INF = 1e9 + 30;
int n;
long long s[N];
vector<int> g[N];
long long sum = 0;
inline void dfs(int v, int p) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) {
      continue;
    }
    long long minimal = INF;
    for (int j = 0; j < g[to].size(); j++) {
      if (g[to][j] == v) {
        continue;
      }
      minimal = min(minimal, s[g[to][j]]);
    }
    if (minimal < s[v]) {
      cout << -1 << endl;
      exit(0);
    }
    if (minimal == INF) {
      s[to] = s[v];
    } else {
      s[to] = minimal;
    }
    for (int j = 0; j < g[to].size(); j++) {
      if (g[to][j] == v) {
        continue;
      }
      dfs(g[to][j], to);
    }
  }
}
inline void dfs2(int v, int p) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) {
      continue;
    }
    sum += (s[to] - s[v]);
    dfs2(to, v);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v;
    cin >> v;
    g[i + 1].push_back(v - 1);
    g[v - 1].push_back(i + 1);
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  dfs(0, 0);
  dfs2(0, 0);
  cout << sum + s[0] << endl;
  return 0;
}
