#include <bits/stdc++.h>
using namespace std;
const int TAM = 2e5 + 5;
int n;
int parent[TAM], acum[TAM], value[TAM], anc[TAM];
vector<int> sons[TAM];
vector<int> adj[TAM];
long long ans = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int x;
  parent[1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> parent[i];
    sons[parent[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> acum[i];
    if (acum[i] == -1) {
      for (int v : sons[i]) {
        adj[parent[i]].push_back(v);
        anc[v] = parent[i];
      }
    }
  }
  value[1] = acum[1];
  queue<int> bfs;
  bfs.push(1);
  ans = acum[1];
  while (bfs.size()) {
    int curr = bfs.front();
    bfs.pop();
    if (curr != 1) {
      if (acum[anc[curr]] > acum[curr]) {
        cout << -1 << endl;
        return 0;
      }
      value[curr] = acum[curr] - acum[anc[curr]];
      ans += value[curr];
    }
    for (int v : adj[curr]) {
      bfs.push(v);
    }
  }
  for (int i = n; i > 0; i--) {
    if (acum[i] != -1 or sons[i].size() == 0) continue;
    int mn = INT_MAX;
    for (int w : sons[i]) mn = min(mn, value[w]);
    ans -= (mn * (sons[i].size() - 1));
  }
  cout << ans << endl;
  return 0;
}
