#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100000 + 5];
vector<int> av(1e5 + 5, -1);
vector<int> sv(1e5 + 5, 0);
vector<int> hv(1e5 + 5, 0);
int n;
bool bad = false;
int dfs(int start, int parent) {
  hv[start] = hv[parent] + 1;
  if (hv[start] % 2 == 1 && sv[start] == -1) {
    bad = 1;
    return -1;
  }
  int minsv = INT_MAX;
  if (hv[start] % 2 == 0) {
    for (auto v : adj[start]) {
      if (v != parent) {
        if (sv[v] == -1) {
          bad = 1;
          return -1;
        }
        minsv = min(sv[v], minsv);
      }
    }
    if (minsv == INT_MAX)
      sv[start] = sv[parent];
    else
      sv[start] = minsv;
    if (minsv < sv[parent]) {
      bad = 1;
      return -1;
    }
  }
  av[start] = sv[start] - sv[parent];
  for (auto v : adj[start]) {
    if (v != parent) dfs(v, start);
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int d;
    cin >> d;
    adj[d].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    int d;
    cin >> d;
    sv[i + 1] = d;
  }
  hv[0] = 0;
  sv[0] = 0;
  int chk = dfs(1, 0);
  if (bad) {
    cout << -1 << endl;
    return 0;
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += av[i + 1];
  }
  cout << ans << endl;
  return 0;
}
