#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define fi first
#define se second
using pii = pair<int,int>;

vector<vector<pii>> vv;

pii dfs(int x, int p){
	pii ret(x,0);
	for(pii y: vv[x]){
		if(y.fi == p) continue;
		pii tmp = dfs(y.fi, x);
		tmp.se += y.se;
		if(tmp.se < ret.se) continue;
		ret = tmp;
	}
	return ret;
}

int main(){
	int n;
	while(cin>>n,n){
		vector<vector<pii>> tt(n);
		vv = vector<vector<pii>>(n);
		vector<int> p(n-1);
		vector<int> d(n-1);
		rep(i,n-1) cin>>p[i];
		rep(i,n-1) cin>>d[i];
		rep(i,n-1){
			int a = i+1;
			int b = p[i]-1;
			tt[a].push_back(pii(b,d[i]));
			tt[b].push_back(pii(a,d[i]));
		}

		int ans = 0;
		rep(i,n){
			if(tt[i].size() == 1) continue;
			for(pii x: tt[i]){
				if(tt[x.fi].size() == 1) continue;
				vv[i].push_back(x);
				ans += x.se;
			}
		}
		pii ty;
		rep(i,n){
			if(vv[i].size()){
				ty = dfs(i, -1);
				break;
			}
		}
		ty = dfs(ty.fi, -1);
		ans -= ty.se;
		rep(i,n-1){
			ans += d[i];
		}		
		cout<<ans<<endl;
	}
}