#include <bits/stdc++.h>
using namespace std;
int n, f[100005], s[100005];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) scanf("%d", &f[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    if (!~s[i]) s[i] = 2e9;
  }
  for (int i = 2; i <= n; i++) s[f[i]] = min(s[i], s[f[i]]);
  for (int i = 1; i <= n; i++) {
    if (s[i] < s[f[i]]) return puts("-1"), 0;
    if (s[i] != 2e9) ans += s[i] - s[f[i]];
  }
  printf("%lld\n", ans);
  return 0;
}
