#include <bits/stdc++.h>
using namespace std;
long long father[100006], cost[100006];
vector<vector<long>> childs(100006, vector<long>());
bool sol = true;
long long totalSum = 0;
void dfs(long node, long depth) {
  long long minCost = 9999999999;
  if ((depth % 2) == 0) {
    cost[node] = cost[father[node]];
    if (childs[node].size() > 0) {
      for (auto child : childs[node]) {
        minCost = min(minCost, cost[child]);
      }
      cost[node] = minCost;
    }
  }
  totalSum += cost[node];
  if (node != 1) {
    totalSum -= cost[father[node]];
  }
  for (auto child : childs[node]) {
    dfs(child, depth + 1);
    if ((depth % 2) == 0) {
      if (cost[child] < cost[father[node]]) {
        sol = false;
      }
    }
  }
}
int main() {
  long n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> father[i];
    childs[father[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> cost[i];
  }
  dfs(1, 1);
  if (sol) {
    cout << totalSum;
  } else {
    cout << "-1";
  }
}
