#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
const int MAX_N = 2e5;
int n;
long long s[MAX_N];
vector<int> g[MAX_N];
bool bad;
long long ans;
void dfs2(int, long long);
void dfs1(int u, long long sp) {
  if (s[u] - sp < 0) {
    bad = 1;
    return;
  }
  ans += s[u] - sp;
  for (int v : g[u]) dfs2(v, s[u]);
}
void dfs2(int u, long long sp) {
  if (g[u].empty()) return;
  long long mn = INF;
  for (int v : g[u]) mn = min(mn, s[v] - sp);
  if (mn < 0) {
    bad = 1;
    return;
  }
  ans += mn;
  for (int v : g[u]) dfs1(v, sp + mn);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    g[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  dfs1(1, 0);
  if (bad) ans = -1;
  cout << ans << "\n";
  return 0;
}
