#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

vector<P> path[805];
int t[805];
int d[805];
int dis[805];

void check(int a,int p){
	if(dis[a]!=-1 || d[a]==1)return;
	dis[a]=p;
	for(int i=0;i<path[a].size();i++){
		check(path[a][i].first,p+path[a][i].second);
	}
}

int main(){
	int n;
	int i,j,k;
	int a,b,c;
	int sd=0,se=0;
	while(cin>>n){
		if(!n)break;
		for(i=0;i<n;i++)path[i].clear();
		memset(d,0,sizeof(d));
		for(i=0;i<n-1;i++){
			cin>>t[i];
			t[i]--;
		}
		sd=0;
		for(i=0;i<n-1;i++){
			cin>>a;
			path[i+1].push_back(make_pair(t[i],a));
			path[t[i]].push_back(make_pair(i+1,a));
			d[i+1]++,d[t[i]]++;
			sd+=a;
		}
		for(i=0;i<n;i++){
			if(d[i]==1)continue;
			for(j=0;j<path[i].size();j++){
				a=path[i][j].first;
				if(d[a]==1)continue;
				sd+=path[i][j].second;
			}
		}
		se=0;
		for(i=0;i<n;i++){
			if(d[i]==1)continue;
			memset(dis,-1,sizeof(dis));
			check(i,0);
			for(j=0;j<n;j++){
				if(se<dis[j])se=dis[j];
			}
		}
		cout<<sd-se<<endl;
	}
}

