#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &first) {
  char c;
  bool neg = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') neg = 1, c = getchar();
  first = c - 48;
  while (isdigit(c = getchar())) first = first * 10 + c - 48;
  if (neg) first = -first;
}
template <typename T>
inline void write(T first) {
  if (first < 0) putchar('-'), first = -first;
  if (first > 9) write(first / 10);
  putchar(first % 10 + 48);
}
const long long N = 1e5;
long long n;
long long p[N + 2], s[N + 2], f[N + 2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (long long i = (2); i <= (n); ++i) cin >> p[i];
  cin >> s[1];
  memset(f, 127, sizeof(f));
  for (long long i = (2); i <= (n); ++i) {
    cin >> s[i];
    if (s[i] == -1) continue;
    if (s[i] < s[p[i]] && s[p[i]] != -1) {
      cout << -1;
      return 0;
    }
    if (s[p[i]] == -1 && s[i] < s[p[p[i]]]) {
      cout << -1;
      return 0;
    }
    if (s[p[i]] == -1) {
      f[p[i]] = min(f[p[i]], s[i]);
    }
  }
  long long res = 0;
  for (long long i = (1); i <= (n); ++i)
    if (s[i] == -1) {
      if (f[i] != f[0])
        s[i] = f[i];
      else
        s[i] = s[p[i]];
    }
  for (long long i = (1); i <= (n); ++i) res += s[i] - s[p[i]];
  cout << res;
  return 0;
}
