#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 5;
const long long Mod = 1e9 + 7;
int fa[Max];
long long sum[Max], ans = 0;
vector<int> son[Max];
bool flag = 0;
void dfs(int now) {
  if (sum[now] == -1) {
    long long temp = 1e9 + 5;
    for (auto to : son[now]) {
      temp = min(temp, sum[to]);
    }
    if (temp != 1e9 + 5)
      sum[now] = temp;
    else
      sum[now] = sum[fa[now]];
  }
  for (auto to : son[now]) dfs(to);
}
void dfs_sum(int now) {
  if (flag) return;
  for (auto to : son[now]) {
    long long temp = sum[to] - sum[now];
    if (temp < 0) flag = 1;
    ans += temp;
    dfs_sum(to);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    son[x].push_back(i);
    fa[i] = x;
  }
  for (int i = 1; i <= n; i++) cin >> sum[i];
  dfs(1);
  dfs_sum(1);
  ans += sum[1];
  if (flag)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
}
