#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
vector<int> adj[maxn];
int par[maxn], s[maxn], h[maxn];
void end() {
  cout << "-1\n";
  exit(0);
}
void dfs(int v) {
  int lo = 0, hi = 1e9 + 100;
  if (par[v] != -1) lo = s[par[v]];
  for (auto u : adj[v])
    if (u != par[v]) {
      h[u] = h[v] + 1;
      dfs(u);
      hi = min(hi, s[u]);
    }
  if (s[v] == -1) {
    if (adj[v].size() == 1)
      s[v] = lo;
    else
      s[v] = hi;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  par[0] = -1;
  for (int i = 1; i < n; i++) {
    cin >> par[i], par[i]--;
    adj[i].push_back(par[i]);
    adj[par[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) cin >> s[i];
  dfs(0);
  long long int sum = 0;
  for (int v = 0; v < n; v++) {
    long long int val = s[v];
    if (par[v] != -1) val -= s[par[v]];
    if (val < 0) end();
    sum += val;
  }
  cout << sum << endl;
  return 0;
}
