#include <iostream>
#include <vector>

using namespace std;

struct Edge {
	int to, cost;
};

struct dfsAns {
	int n, v;
};

int N;
vector< vector<Edge> > edges;

dfsAns dfs(int n, int prev) {
	dfsAns ret = {n, 0};
	for (int i = 0; i < edges[n].size(); ++i) {
		if (edges[n][i].to != prev) {
			dfsAns a = dfs(edges[n][i].to, n);
			if ( edges[edges[n][i].to].size() > 1 ) a.v += edges[n][i].cost;
			if (a.v > ret.v) {
				ret = a;
			}
		}
	}
	return ret;
}

int main() {
	while (cin >> N, N) {
		edges.clear();
		edges.resize(N);

		vector<int> p(N);
		for (int i = 0; i < N-1; ++i) {
			cin >> p[i];
		}
		for (int i = 0; i < N-1; ++i) {
			int d; cin >> d;
			edges[i+1].push_back({p[i]-1, d});
			edges[p[i]-1].push_back({i+1, d});
		}
		dfsAns a = dfs(0, -1);
		a = dfs(a.n, -1);

		int ans = 0;
		for (int i = 0; i < edges.size(); ++i) for (int j = 0; j < edges[i].size(); ++j) {
			ans += edges[i][j].cost;
		}
		ans /= 2;
		for (int i = 0; i < edges.size(); ++i) {
			if (edges[i].size() > 1) {
				for (int j = 0; j < edges[i].size(); ++j) {
					if (edges[edges[i][j].to].size() > 1) ans += edges[i][j].cost;
//					if (i == edges[i][j].to) cout << "error" << endl;
				}
			}
		}
		ans -= a.v;
		cout << ans << endl;
	}
}