#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int p[810];
int d[810];
vector<Pi> graph[810];
int delete_node[810];
int dist[810];
int main(){
	while(1){
		int ans=0;
		cin>>n;
		if(n==0)break;
		REP(i,810)graph[i].clear();
		REP(i,810)delete_node[i]=0;
		for(int i=2;i<=n;i++)cin>>p[i];
		for(int i=2;i<=n;i++)cin>>d[i];
		for(int i=2;i<=n;i++){
			graph[i].push_back(Pi(p[i],d[i]));
			graph[p[i]].push_back(Pi(i,d[i]));
		}
		for(int i=1;i<=n;i++){
			if(graph[i].size()==1){
				ans+=graph[i][0].second;
				delete_node[i]=1;
			}
		}
		for(int i=2;i<=n;i++){
			if(delete_node[i]!=1&&delete_node[p[i]]!=1){
				ans+=(3*d[i]);
			}
		}
		int t1=0;
		for(int i=1;i<n;i++){
			if(delete_node[i])continue;
			REP(k,810)dist[k]=-1;
			dist[i]=0;
			int tdis=0;
			queue<int> q1;
			q1.push(i);
			while(q1.size()){
				int tt1=q1.front();q1.pop();
				for(int k=0;k<graph[tt1].size();k++){
					if(delete_node[graph[tt1][k].first])continue;
					if(dist[graph[tt1][k].first]!=-1)continue;
					dist[graph[tt1][k].first]=dist[tt1]+graph[tt1][k].second;
					q1.push(graph[tt1][k].first);
					tdis=max(tdis,dist[graph[tt1][k].first]);
				}
			}
			t1=max(t1,tdis);
		}
		cout<<ans-t1<<endl;
	}
	return 0;
}
