#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int top, n;
int head[maxn], depth[maxn];
long long val[maxn];
struct node {
  int v, next;
} edge[maxn * 2];
inline void add(int u, int v) {
  edge[top].v = v;
  edge[top].next = head[u];
  head[u] = top++;
}
inline void Init() {
  top = 0;
  memset(head, -1, sizeof(head));
}
long long ans;
bool flag;
void dfs(int u, int father) {
  if (!flag) return;
  if (val[u] == -1) {
    long long mins = 0x3f3f3f3f;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      if (v != father) {
        dfs(v, u);
        mins = min(mins, val[v]);
      }
    }
    val[u] = mins;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      if (v != father) {
        ans += val[v] - mins;
      }
    }
  } else {
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      if (v != father) {
        dfs(v, u);
        if (val[v] >= 0x3f3f3f3f) {
          val[v] = val[u];
        }
        if (val[v] < val[u]) {
          flag = false;
          return;
        }
        ans += val[v] - val[u];
      }
    }
  }
}
int main() {
  cin >> n;
  Init();
  int x;
  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d", &x);
    add(i + 1, x);
    add(x, i + 1);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &val[i]);
  }
  ans = val[1];
  flag = true;
  dfs(1, 0);
  if (!flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
