#include <bits/stdc++.h>
using namespace std;
long long int vmax(vector<long long int> v) {
  long long int max = v[0];
  long long int j;
  for (j = 0; j < v.size(); j++) {
    if (v[j] > max) {
      max = v[j];
    }
  }
  return (max);
}
long long int vmin(vector<long long int> v) {
  long long int min = v[0];
  long long int j;
  for (j = 0; j < v.size(); j++) {
    if (v[j] < min) {
      min = v[j];
    }
  }
  return (min);
}
long long int n;
vector<long long int> v[100000 + 5];
long long int sum[100000 + 5];
long long int ans[100000 + 5];
long long int visited[100000 + 5];
long long int parent[100000 + 5];
long long int h = 0;
void dfs(long long int root) {
  if (sum[root] == -1) {
    if (v[root].size() == 0) {
      ans[root] = 0;
      visited[root] = 1;
      return;
    }
    vector<long long int> m;
    for (int j = 0; j < v[root].size(); j += 1) {
      if (!visited[v[root][j]]) {
        m.push_back(sum[v[root][j]]);
      }
    }
    if (m.size() == 0) {
      ans[root] = 0;
    } else {
      long long int min;
      min = vmin(m);
      ans[root] = min - sum[parent[root]];
      if (ans[root] < 0) {
        h = -1;
      }
      for (int j = 0; j < v[root].size(); j += 1) {
        if (!visited[v[root][j]]) {
          ans[v[root][j]] = sum[v[root][j]] - min;
          if (ans[v[root][j]] < 0) {
            h = -1;
          }
          visited[v[root][j]] = 1;
          dfs(v[root][j]);
        }
      }
    }
  } else {
    for (int j = 0; j < v[root].size(); j += 1) {
      if (!visited[v[root][j]]) {
        visited[v[root][j]] = 1;
        dfs(v[root][j]);
      }
    }
  }
}
void solve() {
  cin >> n;
  memset(visited, 0, sizeof(visited));
  parent[0] = -1;
  for (int j = 1; j < n; j += 1) {
    long long int x;
    cin >> x;
    x--;
    parent[j] = x;
    v[x].push_back(j);
    v[j].push_back(x);
  }
  for (int j = 0; j < n; j += 1) {
    cin >> sum[j];
  }
  ans[0] = sum[0];
  visited[0] = 1;
  for (int j = 0; j < v[0].size(); j += 1) {
    visited[v[0][j]] = 1;
    dfs(v[0][j]);
  }
  if (h == -1) {
    cout << -1 << "\n";
    return;
  }
  long long int second = 0;
  for (int j = 0; j < n; j += 1) {
    second += ans[j];
  }
  cout << second << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
