#include <bits/stdc++.h>
typedef long long ll;
const int maxn = int(1e5) + 7;
std::vector<int> edge[maxn];
int n, dep[maxn];
ll sum[maxn], ans;
void dfs(int u, int pre = 0) {
	dep[u] = dep[pre] + 1;
	if (dep[u] & 1) for (int v : edge[u]) dfs(v, u);
	else {
		if (edge[u].empty()) sum[u] = sum[pre];
		else {
		    sum[u] = 0x3f3f3f3f;
			for (int v : edge[u]) {
				dfs(v, u);
				sum[u] = std::min(sum[u], sum[v]);
			}
		}
	}
}
void calc(int u, int pre = 0) {
	if (sum[u] < sum[pre]) {
		puts("-1");
		exit(0);
	}
	ans += sum[u] - sum[pre];
	for (int v : edge[u])
	    calc(v, u);
}
int main() {
	scanf("%d", &n);
	for (int i = 2, pre; i <= n; i++) scanf("%d", &pre), edge[pre].push_back(i);
	for (int i = 1; i <= n; i++) scanf("%lld", sum + i);
	dfs(1);
	calc(1);
	printf("%lld\n", ans);
	return 0;
}