#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int h[N];
int p[N];
vector<int> adj[N];
int s[N];
int a[N];
bool impo;
void dfs(int u, int depth) {
  if (depth & 1) {
    a[u] = s[u] - (p[u] == -1 ? 0 : s[p[u]]);
  } else {
    int sz = (int)adj[u].size();
    if (!sz) {
      a[u] = 0;
      s[u] = s[p[u]];
    } else {
      int mn = (int)2e9;
      for (int i = 0; i < sz; ++i) {
        mn = min(mn, s[adj[u][i]]);
      }
      if (mn < s[p[u]]) {
        impo = true;
        return;
      }
      a[u] = mn - s[p[u]];
      s[u] = mn;
    }
  }
  for (int i = 0; i < adj[u].size(); ++i) {
    dfs(adj[u][i], depth + 1);
  }
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    cin >> p[i];
    adj[p[i]].push_back(i);
  }
  p[1] = -1;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  impo = false;
  dfs(1, 1);
  if (impo) {
    cout << "-1";
    return 0;
  }
  long long sm = 0;
  for (int i = 1; i <= n; ++i) {
    sm += a[i];
  }
  cout << sm;
}
