#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

int p[800];
int d[800];
int map[800][800];
int count[800];

int dp(int now,int old,int n,int dis,int* dis_max){
	int cost = 0;
	int i;
	for(i=0;i<n;i++){
		if(map[i][now] != 0 && i != old){
			if(count[i] == 1){
				cost += map[i][now];
				if(*dis_max < dis) *dis_max = dis;
			}else{
				cost += 3 * map[i][now] + dp(i,now,n,dis + map[i][now],dis_max);
			}
		}
	}
	return cost;
}

int bridge(int n){
	int i,j;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j] = 0;
		}
		count[i] = 0;
	}
	for(i=1;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
	}
	for(i=1;i<n;i++){
		scanf("%d",&d[i]);
		map[i][p[i]] = map[p[i]][i] = d[i];
		count[i]++;
		count[p[i]]++;
	}

	int cost = INT_MAX;
	int t = 0;
	for(i=0;i<n;i++){
		if(count[i] > 1){
			int c = dp(i,-1,n,0,&t);
			c -= t;
			if(c < cost) cost = c;
		}
	}
	return cost;
}

int main(){
	int n;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		printf("%d\n",bridge(n));
	}
	return 0;
}