#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 1e9 + 7;
long long powermodm(long long x, long long n, long long M) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long power(long long _a, long long _b) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long a[N];
vector<long long> v[N];
long long arr[N];
long long par[N];
bool vis[N];
bool visit[N];
long long ans[N];
long long flag = 1;
long long dfs(long long u) {
  long long m = LLONG_MAX, count = 0, val;
  vis[u] = 1;
  for (long long i = 0; i < v[u].size(); i++) {
    long long node = v[u][i];
    if (vis[node] == 0) {
      count++;
      m = min(m, dfs(node));
    }
  }
  if (count == 0) {
    if (a[u] == -1) {
      val = a[par[u]];
    } else {
      val = a[u];
    }
  } else {
    if (a[u] == -1) {
      val = m;
    } else {
      val = min(a[u], m);
    }
  }
  if (a[u] != -1) {
    if (a[u] - a[1] < 0) {
      flag = 0;
    }
  }
  if (m < a[u]) {
    flag = 0;
  }
  return arr[u] = val;
}
void fun(long long u, long long tmp) {
  visit[u] = 1;
  long long xx = 0;
  ans[u] = max(arr[u] - tmp, xx);
  for (long long i = 0; i < v[u].size(); i++) {
    long long node = v[u][i];
    if (visit[node] == 0) {
      fun(node, tmp + ans[u]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, mx = LLONG_MIN;
  cin >> n;
  par[1] = -1;
  for (long long i = 2; i <= n; i++) {
    cin >> par[i];
    v[par[i]].push_back(i);
    v[i].push_back(par[i]);
  }
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (long long i = 0; i <= n; i++) {
    vis[i] = 0;
    visit[i] = 0;
    ans[i] = 0;
  }
  dfs(1);
  if (flag == 0) {
    cout << -1;
    return 0;
  }
  fun(1, 0);
  long long res = 0;
  for (long long i = 1; i <= n; i++) {
    res += ans[i];
  }
  cout << res << endl;
  return 0;
}
