#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 100100;
int n;
int fa[maxn + 5];
int s[maxn + 5];
int main() {
  scanf("%d", &n);
  fa[0] = -1;
  for (int i = (1), i_end_ = (n); i < i_end_; ++i) scanf("%d", fa + i), --fa[i];
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) scanf("%d", s + i);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    if (s[i] == -1) s[i] = oo;
  long long ans = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    if (s[i] < oo) {
      chkmin(s[fa[i]], s[i]);
    }
  }
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    if (s[i] == oo) s[i] = s[fa[i]];
    if (s[fa[i]] > s[i]) {
      printf("-1\n");
      return 0;
    }
    ans += s[i];
    if (~fa[i]) ans -= s[fa[i]];
  }
  printf("%lld\n", ans);
  return 0;
}
