#include <bits/stdc++.h>
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
using namespace std;
const int maxx = 1e5 + 10;
vector<long long> adj[maxx + 5], s(maxx + 5, 0), a(maxx + 5, 0),
    dp(maxx + 5, 0), used(maxx + 5, 0);
long long nodes;
bool flag = true;
void dfs(int p, int c) {
  if (adj[c].size() == 1 && p != 0) {
    if (s[c] == -1) {
      a[c] = 0;
      s[c] = s[p];
    } else {
      a[c] = s[c] - s[p];
    }
    return;
  }
  long long val = 1e9 + 5;
  for (auto v : adj[c]) {
    if (v != p) {
      val = min(val, s[v]);
      dfs(c, v);
    }
  }
  val = max(val, s[p]);
  if (s[c] == -1) {
    s[c] = val;
  }
  a[c] = s[c] - s[p];
  if (s[p] > s[c]) {
    flag = false;
  }
  return;
}
void bfs(int x) {
  queue<int> q;
  q.push(x);
  used[x] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    long long val = 1e9 + 5;
    for (auto v : adj[u]) {
      if (used[v] == 0) {
        val = min(val, s[v]);
        used[v] = 1;
        q.push(v);
        dp[v] = u;
      }
    }
    int dad = dp[u];
    val = max(val, s[dad]);
    if (adj[u].size() == 1 && dp[u] != 0) {
      if (s[u] == -1) {
        a[u] = 0;
        s[u] = s[dad];
      } else {
        a[u] = s[u] - s[dad];
      }
    } else {
      if (s[u] == -1) {
        s[u] = val;
      }
      a[u] = s[u] - s[dad];
    }
    if (s[dad] > s[u]) {
      flag = false;
    }
  }
}
int main() {
  cin >> nodes;
  for (int i = 2; i <= nodes; i++) {
    long long u;
    cin >> u;
    adj[u].push_back(i);
    adj[i].push_back(u);
  }
  for (int i = 1; i <= nodes; i++) {
    long long u;
    cin >> u;
    s[i] = u;
  }
  s[1] = max((long long)0, s[1]);
  a[1] = s[1];
  bfs(1);
  if (!flag) {
    cout << "-1" << endl;
    return 0;
  }
  long long ans = 0;
  for (int i = 1; i <= nodes; i++) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
