#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > adj(100001);
long long int visited[100001] = {0};
long long int s[100001] = {0};
long long int a[100001] = {0};
long long int parents[100001] = {0};
void BFS(long long int u) {
  queue<long long int> q;
  visited[u] = true;
  q.push(u);
  while (!q.empty()) {
    long long int p = q.front();
    q.pop();
    if (s[p] == -1 && adj[p].size() == 0) {
      a[p] = 0;
      s[p] = s[parents[p]];
    }
    long long int minNodeVal = INT_MAX;
    if (s[p] == -1) {
      for (long long int i = 0; i < adj[p].size(); i++) {
        if (!visited[adj[p][i]])
          minNodeVal =
              ((minNodeVal) < (s[adj[p][i]]) ? (minNodeVal) : (s[adj[p][i]]));
      }
    }
    for (long long int i = 0; i < adj[p].size(); i++) {
      if (!visited[adj[p][i]]) {
        if (s[p] == -1) {
          s[p] = minNodeVal;
        }
        visited[adj[p][i]] = 1;
        q.push(adj[p][i]);
      }
    }
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cout << fixed;
  ;
  clock_t begin = clock();
  long long int n;
  cin >> n;
  parents[0] = -1;
  for (long long int i = 0; i < n - 1; i++) {
    long long int parent;
    cin >> parent;
    adj[parent - 1].push_back(i + 1);
    a[i + 1] = -1;
    parents[i + 1] = parent - 1;
  }
  for (long long int i = 0; i < n; i++) {
    cin >> s[i];
  }
  a[0] = s[0];
  BFS(0);
  long long int res = a[0];
  for (long long int i = 1; i < n; i++) {
    if (a[i] == -1) {
      a[i] = s[i] - s[parents[i]];
    }
    if (a[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
    res += a[i];
  }
  cout << res << endl;
  clock_t end = clock();
  cerr << "Time elapsed: " << double(end - begin) / CLOCKS_PER_SEC << "secs"
       << endl;
  return 0;
}
