#include <bits/stdc++.h>
using namespace std;
const int maxk = 18;
const int maxn = 2e5 + 5;
int N;
long long in[maxn];
long long ans[maxn];
vector<int> graph[maxn];
void DFS(int u, int p, int lvl, long long sum) {
  if (lvl) {
    if (in[u] != -1) {
      cout << -1 << endl;
      exit(0);
    }
    long long minx = 1LL << 51;
    for (int v : graph[u])
      if (v != p) minx = min(minx, in[v] - sum);
    if (minx < 0) {
      cout << -1 << endl;
      exit(0);
    }
    if (minx == (1LL << 51)) minx = 0;
    ans[u] = minx;
  }
  if (!lvl) {
    if (sum > in[u]) {
      cout << -1 << endl;
      exit(0);
    }
    ans[u] = in[u] - sum;
  }
  for (int v : graph[u])
    if (v != p) DFS(v, u, lvl ^ 1, sum + ans[u]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (int i = 2; i <= N; i++) {
    int x;
    cin >> x;
    graph[i].push_back(x);
    graph[x].push_back(i);
  }
  for (int i = 1; i <= N; i++) cin >> in[i];
  DFS(1, 1, 0, 0);
  long long out = 0;
  for (int i = 1; i <= N; i++) out += ans[i];
  cout << out << endl;
  return 0;
}
