#include<stdio.h>
#include<stdlib.h>
#define FOR(k,m,n) for((k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define BFOR(k,m,n) for((k)=(m);(k)>n;(k)--)
#define REVE(i,n) BFOR((i),(n),-1)

#define MAX 1000
#define INF 200000000
#define LEN 100005

typedef struct EdgeS{
	int goTo,weight;
} Edge;
int Q[LEN];
int head,tail,n;
void init(){
	head=tail=0;
}
int isEmpty(){return head==tail;}
int isFull(){return head==(tail+1)%MAX;}
void enqueue(int x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
}
int dequeue(){
	int x = Q[head];
	head = (head+1)%LEN;
	return x;
}




int n;
//??????
Edge graph[MAX][1000];
int graphNum[MAX];
//?????¢
int dist[MAX];

//----??¢??°----
//??°???s??????????????¢????°????
void bfs(int s){
	int i;
	init();
	REP(i,n)dist[i]=INF;
	enqueue(s);
	dist[s]=0;
	int now;
	//?????\???????????????????????§??¢?´¢?????????
	while(!isEmpty()){
		//?????\????????????????????¨??°????????????????????¢?´¢?????????
		int u=dequeue();
		//printf("u:%d \n",u);
		REP(i,graphNum[u]){
			Edge e=graph[u][i];
			//printf("edge %d-%d: %d .",u,i,e.goTo);
			//?????¢?´¢??????????????????????????§???????????¨????¢???????????????????????????´??°?????????
			if(dist[e.goTo]==INF){
				if(graphNum[e.goTo]!=1){
					dist[e.goTo]=dist[u]+e.weight;
					enqueue(e.goTo);
				}
			}
		}
	}
}

int solve(){
	int i;
	//???????????´??????????????????????????????target????±??????????
	bfs(2);
	int maxValue=0;
	int target=0;
	REP(i,n){
		if(dist[i]==INF)continue;
		if(maxValue<dist[i]){
			maxValue=dist[i];
			target=i;
		}
	}
	//printf("target:%d\n",target);
	//target????????????????????????????????¢????±??????????
	bfs(target);
	maxValue=0;
	REP(i,n){
		if(dist[i]==INF)continue;
		if(maxValue<dist[i])maxValue=dist[i];
	}
	//printf("dist~~");
	//REP(i,n+1)printf("%d:%d  ",i,dist[i]);
	//printf("\n");
	return maxValue;
}


int main(){
	//??????????????¨??????
	int p[MAX],d[MAX];
	int i,j;
	
	while(1){
		//?????????
		REP(i,MAX)REP(j,100){graph[i][j].goTo=0;graph[i][j].weight=0;}
		REP(i,MAX)graphNum[i]=0;
		//??\???
		scanf("%d",&n);
		if(n==0)break;
		FOR(i,2,n+1)scanf("%d",&p[i]);
		FOR(i,2,n+1)scanf("%d",&d[i]);

		//?????±???????´?
		FOR(i,2,n+1){
			graph[i][graphNum[i]].goTo   = p[i];
			graph[i][graphNum[i]].weight = d[i];
			graphNum[i]++;
			
			graph[p[i]][graphNum[p[i]]].goTo = i;
			graph[p[i]][graphNum[p[i]]].weight=d[i];
			graphNum[p[i]]++;
		}
		
		//FOR(i,1,n+1)printf("%d:%d  ",i,graphNum[i]);
		//printf("\n");
		//???????????????????????????????°????????????????
		//?????¨????????§?????????????????????????????¨????????¨?????????????¶??????????????????????
		int ans=0;
		FOR(i,2,n+1)ans+=d[i];
		//printf("No1:%d\n",ans);
		//????????¬?????????????????????????????£???????????£?????????????????????????????§???????????????????¶???????
		//?????????????§????????????????????????§????\???????????????????????????§???
		//????????\?¶????????????????????????????
		FOR(i,2,n+1){
			if(graphNum[i]!=1 && graphNum[p[i]]!=1)
				ans+=d[i]*2;
		}
		//printf("No2:%d\n",ans);
		//??¢?????????????????????????????¨????????????????????????????????????????????????????????????????????????
		//??????????????§???????????°?????????
		//?±?????????°??????????????????????????§??????
		ans-=solve();
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 7780