#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 7;
const int infint = (int)1e8 + 3;
const long long inf = (long long)1e18;
long long n, a[MAXN], p[MAXN], s[MAXN], h[MAXN];
vector<int> child[MAXN];
bool nt = 1;
void dfs(int u) {
  if (h[u] % 2) {
    if (child[u].size() == 0)
      a[u] = 0;
    else {
      long long mn = infint;
      for (auto v : child[u]) {
        if (s[p[u]] > s[v]) nt = 0;
        mn = min(mn, s[v] - s[p[u]]);
      }
      a[u] = mn, s[u] = s[p[u]] + a[u];
    }
  } else if (u == 1)
    a[u] = s[u];
  else
    a[u] = s[u] - s[p[u]];
  for (auto v : child[u]) dfs(v);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
    h[i] = h[p[i]] + 1;
    child[p[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  dfs(1);
  if (nt == 0) return cout << -1, 0;
  long long sum = 0;
  for (int i = 1; i <= n; i++) sum += a[i];
  cout << sum;
}
