#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n - 1], b[n];
  vector<int> adj[n + 1];
  vector<int> vis(n + 1, 0);
  vector<int> dis(n + 1, 1000000007);
  vector<int> val(n + 1, -1);
  vector<int> res(n + 1, 0);
  vector<int> parent(n + 1, -1);
  vector<int> daughter[n + 1];
  for (long long i = 0; i < n - 1; i++) {
    cin >> a[i];
    adj[a[i]].push_back(i + 2);
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    val[i + 1] = b[i];
  }
  queue<int> q;
  q.push(1);
  vis[1] = 1;
  dis[1] = 1;
  res[1] = val[1];
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    int mini = 1000000007;
    if (dis[v] % 2 == 1 && dis[v] != 1) {
      res[v] = val[v] - (res[parent[v]] + val[parent[parent[v]]]);
    } else if (dis[v] % 2 == 0) {
      for (int i : adj[v]) {
        mini = min(mini, val[i] - val[parent[v]]);
      }
      if (mini < 0) {
        cout << -1 << '\n';
        return 0;
      }
      if (mini != 1000000007) {
        res[v] = mini;
      }
    }
    for (int i : adj[v]) {
      if (vis[i] == 0) {
        parent[i] = v;
        q.push(i);
        vis[i] = 1;
        dis[i] = dis[v] + 1;
      }
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (res[i] < 0) {
      cout << -1 << '\n';
      return 0;
    }
    sum = sum + res[i];
  }
  cout << sum << '\n';
}
