#include<bits/stdc++.h>
using namespace std;
int n;
struct edge{
  int to,c;
};
vector<edge> G[811];
int dp[811][811][2];
int solve(int id,int pr,int fl){
  if( dp[id][pr][fl] != -1 ) return dp[id][pr][fl];
  vector<int> nex;
  int ret = 0;
  int tc = 0;
  for(int i=0;i<(int)G[id].size();i++){
    edge e = G[id][i];
    if( e.to == pr ){
      tc= e.c;
     continue;
    }
    if( G[e.to].size() == 1 ) nex.push_back( e.c );
    else nex.push_back( solve( e.to, id, 1 ) + e.c*2 );    
    ret += nex.back();
  }
  int sum = ret;
  // if( fl == 1 )cout << id << " " << pr << " "<< fl << " " << ret + tc << endl;
   if(fl==1) return dp[id][pr][fl] = ret + tc;
  for(int i=0,j=0;i<(int)G[id].size();i++){
    edge e = G[id][i];
    if( e.to == pr ) continue;
    if( G[e.to].size() == 1 ) ret = min( ret, sum - nex[j] + e.c );
    else ret = min( ret, sum - nex[j] + solve( e.to, id, 0 ) + e.c );
    j++;
  }
  // cout << id << " " << pr << " "<< fl << " "<< ret + tc << endl;
  return dp[id][pr][fl] = ret + tc;
}

int main(){
  while( cin >>n && n ) {
    memset(dp,-1,sizeof(dp));
    int p[811]={};
    for(int i=1;i<n;i++)
      cin >> p[i];
    for(int i=1;i<n;i++){
      int d; cin >> d; p[i]--;
      G[i].push_back((edge){p[i],d});
      G[p[i]].push_back((edge){i,d});
    }
    /*
    for(int i=0;i<n;i++){
      cout << " i " << i << endl;
      for(int j=0;j<(int)G[i].size();j++){
	cout << " - > " << G[i][j].to << endl;
      }
    }
    */
    int res = (1<<30);
    for(int i=0;i<n;i++){
      if( G[i].size() == 1 ){
	res = min(res,solve(G[i][0].to,i,0));
      }
    }
    cout << res << endl;
    for(int i=0;i<n;i++) G[i].clear();
  }
}