#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int maxn = 2e5 + 10;
struct node {
  long long v, next;
} edge[maxn * 2 + 10];
long long cnt, head[maxn], sum[maxn], fa[maxn], sd[maxn];
void add(long long x, long long y) {
  edge[cnt].next = head[x];
  edge[cnt].v = y;
  head[x] = cnt++;
}
void dfs(long long x, long long fa2) {
  long long i, v;
  sd[x] = max(sd[x], sum[x]);
  for (i = head[x]; i != -1; i = edge[i].next) {
    v = edge[i].v;
    if (v == fa2) continue;
    fa[v] = x;
    sd[v] = max(sd[v], sd[x]);
    dfs(v, x);
  }
}
void dfs2(long long x, long long fa) {
  long long tot, v, i, ret;
  tot = 0;
  for (i = head[x]; i != -1; i = edge[i].next) {
    v = edge[i].v;
    if (v == fa) continue;
    tot++;
  }
  if (tot == 0) {
    if (sum[x] == -1) {
      sum[x] = sd[x];
    }
    return;
  }
  for (i = head[x]; i != -1; i = edge[i].next) {
    v = edge[i].v;
    if (v == fa) continue;
    dfs2(v, x);
  }
  if (sum[x] != -1) return;
  ret = INF;
  for (i = head[x]; i != -1; i = edge[i].next) {
    v = edge[i].v;
    if (v == fa) continue;
    ret = min(ret, sum[v]);
  }
  sum[x] = ret;
}
int main() {
  long long n, i, flag, ans, p;
  scanf("%I64d", &n);
  memset(head, -1, sizeof(head));
  cnt = 0;
  for (i = 2; i <= n; i++) {
    scanf("%I64d", &p);
    add(p, i);
    add(i, p);
  }
  memset(fa, -1, sizeof(fa));
  memset(sd, 0, sizeof(sd));
  memset(sum, -1, sizeof(sum));
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &sum[i]);
  }
  flag = 0;
  dfs(1, -1);
  for (i = 1; i <= n; i++) {
    if (sum[i] == -1) continue;
    if (sum[i] < sd[i]) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    printf("-1\n");
    return 0;
  }
  dfs2(1, -1);
  ans = 0;
  for (i = 1; i <= n; i++) {
    if (i == 1) {
      ans += sum[1];
      continue;
    }
    ans += sum[i] - sum[fa[i]];
  }
  printf("%I64d\n", ans);
  return 0;
}
