//1196
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef pair<int,int> P;

const int MAX_N=800,INF=1E8;

int n;
int p[MAX_N];
int d[MAX_N];

vector<P> G[MAX_N];

int dist[MAX_N];
int pre[MAX_N];
bool used[MAX_N];

void bfs(int s){
	fill(dist,dist+n,INF);
	fill(pre,pre+n,-1);
	dist[s]=0;
	queue<int> q;
	q.push(s);
	while(!q.empty()){
		int v=q.front();
		q.pop();
		REP(i,G[v].size()){
			P p=G[v][i];
			if (dist[p.first]==INF && G[p.first].size()!=1){
				dist[p.first]=dist[v]+p.second;
				pre[p.first]=v;
				q.push(p.first);
			}
		}
	}
}

int main(){
	do{
		scanf("%d",&n);
		if (n){
			fill(used,used+n,false);
			REP(i,n){
				G[i].clear();
			}
			REP(i,n-1){
				scanf("%d",&p[i+1]);
				p[i+1]--;
			}
			REP(i,n-1){
				scanf("%d",&d[i+1]);
			}
			FOR(i,1,n){
				G[i].push_back(P(p[i],d[i]));
				G[p[i]].push_back(P(i,d[i]));
			}
			bfs(0);
			int s=0;
			REP(i,n){
				if (dist[i]!=INF){
					if (dist[i]>dist[s]){
						s=i;
					}
				}
			}
			bfs(s);
			int g=s;
			REP(i,n){
				if (dist[i]!=INF){
					if (dist[i]>dist[g]){
						g=i;
					}
				}
			}
			for(int i=g;i!=-1;i=pre[i]){
				used[i]=true;
			}
			int ans=0;
			FOR(i,1,n){
				if (G[i].size()==1 || G[p[i]].size()==1){
					ans+=d[i];
				}
				else if (used[i] && used[p[i]]){
					ans+=d[i]*2;
				}
				else{
					ans+=d[i]*3;
				}
			}
			printf("%d\n",ans);
		}
	}while(n);
	return 0;
}