#include <bits/stdc++.h>
const int oo = 0x7fffffff;
const long long OO = 0x7fffffffffffffff;
template <class T>
std::ostream& operator<<(std::ostream& O, const std::vector<T>& V) {
  for (const T& x : V) O << x << " ";
  O << "\n";
  return O;
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& O, const std::pair<T1, T2>& P) {
  return O << "(" << P.first << ", " << P.second << ")";
}
using namespace std;
struct tree {
  int n;
  vector<vector<int> > adj;
  vector<int> sum, val;
  tree(int n) : n(n), adj(n), sum(n), val(n) {
    for (int u = 1, p; u < n; ++u) {
      cin >> p;
      --p;
      adj[p].push_back(u);
    }
    for (int i = 0; i < n; ++i) {
      cin >> sum[i];
    }
    dfs(0, 0);
  }
  void dfs(int u, int s) {
    if (sum[u] >= 0)
      val[u] = sum[u] - s;
    else {
      sum[u] = oo;
      if (adj[u].size() == 0) sum[u] = s;
      for (auto v : adj[u]) sum[u] = std::min(sum[u], sum[v]);
      val[u] = sum[u] - s;
    }
    for (auto v : adj[u]) {
      dfs(v, sum[u]);
    }
  }
  long long solve() {
    long long s = 0;
    for (auto x : val)
      if (x < 0)
        return -1;
      else
        s += x;
    return s;
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  ;
  int n;
  cin >> n;
  tree t(n);
  cout << t.solve() << "\n";
  return 0;
}
