#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
vector<int> adj[MAX_N];
int n;
int s[MAX_N];
int a[MAX_N];
vector<pair<int, int> > save[MAX_N];
void DFS(int u, int father, int sum, int prevsum) {
  if (s[u] == -1) {
    for (int i = 0; i < (int)adj[u].size(); i++) {
      int v = adj[u][i];
      if (v == father) {
        continue;
      }
      save[u].push_back(make_pair(v, s[v] - sum));
    }
  } else {
    if (u > 1) {
      if (s[u] < prevsum) {
        cout << -1;
        exit(0);
      }
    }
  }
  for (int i = 0; i < (int)adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == father) {
      continue;
    }
    if (s[v] == -1) {
      DFS(v, u, sum, sum);
    } else {
      DFS(v, u, s[v], sum);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    adj[i].push_back(p);
    adj[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
  }
  DFS(1, -1, s[1], 0);
  a[1] = s[1];
  long long res = 0;
  for (int i = 2; i <= n; i++) {
    if (save[i].empty()) {
      continue;
    }
    int mini = save[i][0].second;
    for (int j = 0; j < (int)save[i].size(); j++) {
      pair<int, int> tmp = save[i][j];
      mini = min(mini, tmp.second);
    }
    a[i] = mini;
    for (int j = 0; j < (int)save[i].size(); j++) {
      pair<int, int> tmp = save[i][j];
      a[tmp.first] = tmp.second - mini;
    }
  }
  for (int i = 1; i <= n; i++) {
    res += 1LL * a[i];
  }
  cout << res;
  return 0;
}
