#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int fa[maxn];
int head[maxn], tot;
struct edge {
  int to, nex;
} E[maxn << 1];
void addedge(int a, int b) {
  E[++tot].to = b;
  E[tot].nex = head[a];
  head[a] = tot;
}
int flag;
int sum[maxn], val[maxn];
void dfs(int now, int dep) {
  if (flag) return;
  if (dep % 2 == 0) {
    if (head[now] == 0) {
      sum[now] = sum[fa[now]];
      val[now] = 0;
      return;
    }
    int minn = 0x3f3f3f3f;
    for (int i = head[now]; i; i = E[i].nex) {
      int v = E[i].to;
      minn = min(minn, sum[v]);
    }
    if (minn < sum[fa[now]]) {
      flag = 1;
      return;
    } else {
      val[now] = minn - sum[fa[now]];
      sum[now] = sum[fa[now]] + val[now];
    }
    for (int i = head[now]; i; i = E[i].nex) {
      int v = E[i].to;
      dfs(v, dep + 1);
    }
  } else {
    val[now] = sum[now] - sum[fa[now]];
    for (int i = head[now]; i; i = E[i].nex) {
      int v = E[i].to;
      dfs(v, dep + 1);
    }
  }
}
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    fa[i] = x;
    addedge(x, i);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &sum[i]);
  val[1] = sum[1];
  dfs(1, 1);
  if (flag) {
    printf("-1\n");
    return 0;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += val[i];
  printf("%lld\n", ans);
  return 0;
}
