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

#define MAX_N 810

int cost[MAX_N][MAX_N];
int size[MAX_N];
int p[MAX_N], d[MAX_N];
int N;
int res1 = 0, res2 = 0, rmax = 0;

typedef struct{
	int isl, len;
}result;

int max(int a, int b){
	if(a > b) return a;
	else return b;
}

result dfs(int is, int prei, int len){//????????¶???????????¶????????¢->?????¢????????§??¨????????¶??¨???????????¢
	result res1, res2;
	int i;
	res1.isl = is; res1.len= len;
	for(i = 0; i < N; i++){
		if(i == is || i == prei) continue;
		if(cost[is][i] > 0){
			res2 = dfs(i, is, len+cost[is][i]);
			if(res1.len < res2.len) res1 = res2;
		}
	}
	return res1;
}

int main(int argc, char const *argv[])
{
	int i, j;
	while(1){
		scanf("%d", &N);
		if(N == 0) break;
		res1 = 0 ; res2 = 0;
		for(i = 0; i < N; i++)for(j = 0; j < N; j++) cost[i][j] = 0;
		for(i = 0; i < N; i++) size[i] = 0;
		for(i = 1; i < N; i++){ scanf("%d", &p[i]); p[i]--; }
		for(i = 1; i < N; i++) scanf("%d", &d[i]);
		for(i = 1; i < N; i++){
			cost[i][p[i]] = d[i];
			cost[p[i]][i] = d[i];
			size[p[i]]++;
			size[i]++;
		}
		for(i = 0; i < N; i++){
			if(size[i] == 1){
				for(j = 0;j < N;j++){
					if(cost[i][j] != 0){
						res1 += cost[i][j];
						cost[i][j] = 0;
						cost[j][i] = 0;
					}
				}
			}
		}
		for(i = 0; i < N; i++)for(j = i+1; j < N;j++) res2 += cost[i][j];
		result r;
		for(i = 0; i < N; i++){
			if(size[i] > 1){
				r = dfs(i,-1,0);
				r = dfs(r.isl,-1,0);
				break;
			}
		}

		printf("%d\n", res1+res2*3-r.len);
	}
	return 0;
}