#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N;
int P[800],d[800],bridge_connect_num[801],min_dist[801][801];

void func(){

	for(int i = 1; i <= N; i++)bridge_connect_num[i] = 0;

	for(int i = 1; i <= N; i++){
		for(int k = 1; k <= N; k++){
			if(i != k)min_dist[i][k] = BIG_NUM;
			else{
				min_dist[i][k] = 0;
			}
		}
	}

	for(int i = 1; i <= N-1; i++){
		scanf("%d",&P[i]);
		bridge_connect_num[i+1]++;
		bridge_connect_num[P[i]]++;
	}

	for(int i = 1; i <= N-1; i++){
		scanf("%d",&d[i]);
		min_dist[i+1][P[i]] = d[i];
		min_dist[P[i]][i+1] = d[i];
	}

	vector<int> Node;
	for(int i = 1; i <= N; i++){
		if(bridge_connect_num[i] > 1){
			Node.push_back(i);
		}
	}

	for(int mid = 0; mid < Node.size();mid++){
		for(int st = 0; st < Node.size();st++){
			if(min_dist[Node[st]][Node[mid]] == BIG_NUM)continue;
			for(int gl = 0; gl < Node.size();gl++){
				if(min_dist[Node[mid]][Node[gl]] == BIG_NUM)continue;
				min_dist[Node[st]][Node[gl]] = min(min_dist[Node[st]][Node[gl]],min_dist[Node[st]][Node[mid]]+min_dist[Node[mid]][Node[gl]]);
			}
		}
	}

	int maximum = -1;
	for(int from = 1; from <= N; from++){
		for(int to = 1; to <= N; to++){
			if(min_dist[from][to] != BIG_NUM && bridge_connect_num[from] > 1 && bridge_connect_num[to] > 1){
				maximum = max(maximum,min_dist[from][to]);
			}
		}
	}

	int ans = 0;
	for(int i = 1; i <= N-1; i++){
		if(bridge_connect_num[i+1] == 1 || bridge_connect_num[P[i]] == 1){
			ans += d[i];
		}else{
			ans += 3*d[i];
		}
	}

	ans -= maximum;

	printf("%d\n",ans);

}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}