#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args>
inline string arrStr(T arr, int n) {
  stringstream s;
  s << "[";
  for (int i = 0; i < n - 1; i++) s << arr[i] << ",";
  s << arr[n - 1] << "]";
  return s.str();
}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template <typename T>
inline void __evars_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T>
inline void __evars_out_var(T *val) {
  cerr << arrStr(val, 10);
}
template <typename T>
inline void __evars_out_var(T val) {
  cerr << val;
}
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template <typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __evars_out_var(a);
  cerr << "; ";
  __evars(++it, args...);
}
template <class t = int>
t get() {
  t a;
  std::cin >> a;
  return a;
}
int r, c, n, k;
class graphNode {
 public:
  vector<int> adj, wt;
  int sum;
  graphNode() { sum = 1; }
};
class graph {
 public:
  int n;
  vector<graphNode> nodes;
  vector<int> res;
  graph(int nodeNumber) {
    n = nodeNumber + 1;
    nodes.resize(n);
    res.resize(n, 0);
  }
  void addDirEdge(int a, int b, bool weighted = false, int weight = 0) {
    nodes[a].adj.push_back(b);
    if (weighted) {
      nodes[a].wt.push_back(weight);
    }
  }
  int findans() {
    vector<int> visited(n);
    dfsUtil(1, visited, true, nodes[1].sum);
    long long sres = 0;
    for (c = 1; c < n; c++) {
      if (res[c] < 0) {
        return cout << -1, 0;
      }
      sres += res[c];
    }
    cout << sres + nodes[1].sum;
    ;
    return 1;
  }
  void dfsUtil(int itr, vector<int> &visited, bool idk, int s) {
    visited[itr] = 1;
    int m = INT_MAX;
    if (nodes[itr].adj.size() == 0) return;
    for (int i = 0; i < nodes[itr].adj.size(); i++) {
      if (!visited[nodes[itr].adj[i]]) {
        if (idk)
          dfsUtil(nodes[itr].adj[i], visited, !idk, nodes[itr].sum);
        else {
          m = min(m, nodes[nodes[itr].adj[i]].sum);
          dfsUtil(nodes[itr].adj[i], visited, !idk, s);
        }
      }
    };
    if (!idk) {
      res[itr] = m - s;
      for (int i = 0; i < nodes[itr].adj.size(); i++) {
        res[nodes[itr].adj[i]] = nodes[nodes[itr].adj[i]].sum - m;
      }
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  ;
  int n;
  cin >> n;
  graph mygraph(n);
  for (c = 0; c < n - 1; c++) {
    mygraph.addDirEdge(get(), c + 2);
  }
  for (c = 1; c < n + 1; c++) {
    cin >> mygraph.nodes[c].sum;
  }
  mygraph.findans();
}
