#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;

struct Info{
	Info(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to,cost;
};

struct Data{
	Data(int arg_node_id,int arg_cost_sum){
		node_id = arg_node_id;
		cost_sum = arg_cost_sum;
	}
	bool operator<(const struct Data &arg) const{
		return cost_sum > arg.cost_sum;
	};
	int node_id,cost_sum;
};

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]]++;
	}

	vector<Info> V[N+1];

	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];
		V[i+1].push_back(Info(P[i],d[i]));
		V[P[i]].push_back(Info(i+1,d[i]));
	}

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

	int min_dist[N+1];
	for(int i = 1; i <= N;i++){
		min_dist[i] = BIG_NUM;
	}

	min_dist[Node[0]] = 0;

	priority_queue<Data> Q;

	for(int i = 0; i < V[Node[0]].size();i++){
		if(bridge_connect_num[V[Node[0]][i].to] == 1)continue;
		min_dist[V[Node[0]][i].to] = V[Node[0]][i].cost;
		Q.push(Data(V[Node[0]][i].to,min_dist[V[Node[0]][i].to]));
	}

	int index;
	while(!Q.empty()){
		if(Q.top().cost_sum > min_dist[Q.top().node_id]){
			Q.pop();
		}else{
			index = Q.top().node_id;
			Q.pop();

			for(int i = 0; i < V[index].size();i++){
				if(min_dist[V[index][i].to] > min_dist[index]+V[index][i].cost && bridge_connect_num[V[index][i].to] > 1){
					min_dist[V[index][i].to] = min_dist[index]+V[index][i].cost;
					Q.push(Data(V[index][i].to,min_dist[V[index][i].to]));
				}
			}
		}
	}

	int maximum = -1,max_index;
	for(int i = 1; i < N; i++){
		if(min_dist[i] != BIG_NUM && maximum < min_dist[i]){
			maximum = min_dist[i];
			max_index = i;
		}
	}

	int minus;

	if(Node.size() == 1){
		minus = 0;
	}else{

		for(int i = 1; i <= N; i++)min_dist[i] = BIG_NUM;
		min_dist[max_index] = 0;

		for(int i = 0; i < V[max_index].size();i++){
			if(bridge_connect_num[V[max_index][i].to] == 1)continue;
			min_dist[V[max_index][i].to] = V[max_index][i].cost;
			Q.push(Data(V[max_index][i].to,V[max_index][i].cost));
		}

		while(!Q.empty()){
			if(Q.top().cost_sum > min_dist[Q.top().node_id]){
				Q.pop();
			}else{
				index = Q.top().node_id;
				Q.pop();

				for(int i = 0; i < V[index].size();i++){
					if(min_dist[V[index][i].to] > min_dist[index]+V[index][i].cost && bridge_connect_num[V[index][i].to] > 1){
						min_dist[V[index][i].to] = min_dist[index]+V[index][i].cost;
						Q.push(Data(V[index][i].to,min_dist[V[index][i].to]));
					}
				}
			}
		}
		minus = -1;
		for(int i = 1; i < N; i++){
			if(min_dist[i] != BIG_NUM && minus < min_dist[i]){
				minus = min_dist[i];
			}
		}
	}

	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 -= minus;

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

}

int main(){

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

		func();
	}

	return 0;
}

Measured memory_bytes: 5796