#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long dr[4] = {0, 0, 1, -1};
long long dc[4] = {1, -1, 0, 0};
long long ddr[8] = {0, 0, 1, -1, 1, -1, 1, -1};
long long ddc[8] = {1, -1, 0, 0, 1, -1, -1, 1};
long long ddr1[8] = {1, 1, -1, -1, 2, 2, -2, -2};
long long ddc1[8] = {2, -2, 2, -2, 1, -1, 1, -1};
vector<long long> v[200003];
long long vis[200003], level[200003], parent[200003];
long long val[200003], sum[200003], n;
bool flag;
void dfs(long long node, long long lvl, long long par) {
  level[node] = lvl;
  parent[node] = par;
  for (auto child : v[node]) {
    if (child != par) {
      dfs(child, lvl + 1, node);
    }
  }
}
void dfs1(long long node) {
  if (level[node] % 2 == 1 && parent[node] != -1) {
    long long up1 = parent[node];
    long long up2 = parent[up1];
    if (sum[node] - sum[up2] < 0) flag = 1;
    if (val[up1] == -2)
      val[up1] = sum[node] - sum[up2];
    else
      val[up1] = min(val[up1], sum[node] - sum[up2]);
  }
  vis[node] = 1;
  for (auto child : v[node]) {
    if (vis[child] == 0) {
      dfs1(child);
    }
  }
}
void dfs2(long long node) {
  if (level[node] % 2 == 1 && parent[node] != -1) {
    long long up1 = parent[node];
    long long up2 = parent[up1];
    val[node] = sum[node] - val[up1] - sum[up2];
  }
  vis[node] = 1;
  for (auto child : v[node]) {
    if (vis[child] == 0) {
      dfs2(child);
    }
  }
}
int32_t main() {
  fast();
  cin >> n;
  for (long long i = 2; i < n + 1; i++) {
    long long x;
    cin >> x;
    v[x].emplace_back(i);
    v[i].emplace_back(x);
  }
  for (long long i = 1; i < n + 1; i++) {
    cin >> sum[i];
    val[i] = -2;
  }
  val[1] = sum[1];
  dfs(1, 1, -1);
  dfs1(1);
  memset(vis, 0, sizeof(vis));
  dfs2(1);
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    if (val[i] < 0) continue;
    ans += val[i];
  }
  if (flag)
    cout << "-1";
  else
    cout << ans << "\n";
}
