#include <bits/stdc++.h>
using namespace std;
const int m = 1e5;
vector<vector<int>> A(m);
int p[m];
int s[m];
void dfs(int x) {
  int minn = 1e9 + 1;
  for (int i = 0; i < A[x].size(); i++) {
    if (s[A[x][i]] < minn) minn = s[A[x][i]];
    dfs(A[x][i]);
  }
  if (s[x] == -1) {
    if (minn == 1e9 + 1)
      s[x] = s[p[x] - 1];
    else
      s[x] = minn;
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  p[0] = 1;
  for (int i = 1; i < n; i++) {
    cin >> p[i];
    A[p[i] - 1].push_back(i);
  }
  for (int i = 0; i < n; i++) cin >> s[i];
  dfs(0);
  long long summ = s[0];
  for (int i = 0; i < n; i++) {
    if (s[i] < s[p[i] - 1]) {
      cout << -1;
      return 0;
    } else
      summ += s[i] - s[p[i] - 1];
  }
  cout << summ;
}
