#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
 
int p[800];
int d[800];
int map[800][800];
int count[800];
 
void dp(int now,int old,int n,int now_dis,int* dis_max,int* point){
    int cost = 0;
    int i;
    for(i=0;i<n;i++){
        if(map[i][now] != 0 && i != old){
            if(count[i] == 1){
                if(now_dis > *dis_max){
                    *dis_max = now_dis;
                    *point = now;
                }
            }else{
                dp(i,now,n,now_dis+map[i][now],dis_max,point);
            }
        }
    }
}
 
int bridge(int n){
    int i,j;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            map[i][j] = 0;
        }
        count[i] = 0;
}
    for(i=1;i<n;i++){
        scanf("%d",&p[i]);
        p[i]--;
    }
    for(i=1;i<n;i++){
        scanf("%d",&d[i]);
        map[i][p[i]] = map[p[i]][i] = d[i];
        count[i]++;
        count[p[i]]++;
    }
 
    int cost = 0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(count[i] == 1 || count[j] == 1) cost += map[i][j];
            else cost += (3 * map[i][j]);
        }
    }
 
    int point = -1;
    int maxint = -1;
    for(i=0;i<n;i++){
        if(count[i] > 1){
            dp(i,-1,n,0,&maxint,&point);
            break;
        }
    }
    maxint = -1;
    dp(point,-1,n,0,&maxint,&point);
    cost -= maxint;
    return cost;
}
 int main(){
    int n;
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        printf("%d\n",bridge(n));
    }
    return 0;
}