#include <stdio.h>
#include <stdbool.h>
int memo[805][805]={0};
int num[805]={0};
int dummy[805]={0};
bool ch[805]={0};
int n,max=0;

typedef struct{
  int now;
  int dis;
}queue;

void solve(int t);
void reset();

int main(void){
  int ans=0,i,j;
  while(1){
    scanf("%d\n",&n);
    if(n==0)break;
    max=0;
    ans=0;
    for(i=2;i<=n;i++){
      scanf("%d",&dummy[i]);
      num[i]++;
      num[dummy[i]]++;
    }
    for(i=2;i<=n;i++){
      scanf("%d",&memo[i][dummy[i]]);
      memo[dummy[i]][i]=memo[i][dummy[i]];
    }
    for(i=1;i<n;i++)for(j=i+1;j<=n;j++){
	if(num[i]==1||num[j]==1)ans+=memo[i][j];
	else ans+=memo[i][j]*3;
    }
    for(i=1;i<=n;i++){
      reset();
      if(num[i]==1)continue;
      solve(i);
    }
    printf("%d\n",ans-max);
    for(i=1;i<=n;i++)for(j=1;j<=n;j++)memo[i][j]=0;
    for(i=1;i<=n;i++){
      num[i]=0;
      dummy[i]=0;
    }
  }
  return 0;
}

void solve(int t){
  queue qu[805];
  int i,j,co=1,nnum=0;;
  queue now;
  qu[0].dis=0;
  qu[0].now=t;
  ch[t]=1;
  while(co>nnum){
    now.dis=qu[nnum].dis;
    now.now=qu[nnum].now;
    if(max<now.dis){
      // printf("%d %d\n",now.dis,now.now);
      max=now.dis;
    }
    for(i=1;i<=n;i++){
      if(ch[i]==1||memo[i][now.now]==0)continue;
      qu[co].dis=now.dis+memo[i][now.now];
      qu[co].now=i;
      ch[i]=1;
      co++;
    }
    //for(i=1;i<=n;i++)printf("%d ",ch[i]);
    //printf("\n");
    nnum++;
  }
  //printf("\n");
}
void reset(){
  int i;
  for(i=1;i<=n;i++){
    if(num[i]==1)ch[i]=1;
    else ch[i]=0;
  }
}

