#include <stdio.h>
#include <stdlib.h>

#define unknown -1
#define MAXN 1000
#define INF 1000000
#define QSIZE 1000000

//////???????????¢??°//////
int max(int a, int b){ if(a>b) return a; else return b;}

//////?????\?????¢??£//////
static int head, tail;
static int q[QSIZE];
void qinit(){ head=tail=0; }
int qisEmpty(void){ return head == tail; }
void enqueue(int i){ q[tail++] = i; tail %= QSIZE; }
int dequeue(void){ int x=q[head]; head=(head+1)%QSIZE; return x; }
//////////////////////

//???
typedef struct {
    int gt; //?????????
    int w; //?????????
} Edge;

Edge g[MAXN][1000];
int gnum[MAXN];
int dist[MAXN];
int n; //??¶?????°

//???????????§??¨?????´???????±?????????¢??°???
int solve(); //c3??????????????´
void bfs(int);

//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2407239#1???????????????????????????

/////??????/////
//???????????¶???????????£?????????????????°??????????????¶????¬???°???degree?????¨??????
//(1)degree=1?????¶??????????????¶??????????????¨?????????????????§????????????????????£??????????????¨??°??????????????£?????????????????§?????????
//(2)degree>=2?????¶???????????????????????????????????????????????¶????¨??????????????????°???????????????
//(3)????°????????????????(1)+2*(2)-??¨?????´?????§??¨????????????
//////////////

int main(void){
    int i,j,ans,p[MAXN],d[MAXN];
    for(;;){
        scanf("%d", &n);
        if(n==0) break;
        //?????????
        for(i=0;i<MAXN;i++){
            gnum[i] = 0;
            for(j=0;j<MAXN;j++){
                g[i][j].gt = 0;
                g[i][j].w = 0;
            }
        }
        //???????????????????????????
        for(i=2;i<=n;i++)
            scanf("%d", &p[i]);
        //????????????????????????
        for(i=2;i<=n;i++)
            scanf("%d", &d[i]);

        for(i=2;i<=n;i++){
            g[i][gnum[i]].gt = p[i];
            g[i][gnum[i]].w = d[i];
            gnum[i]++;
            g[p[i]][gnum[p[i]]].gt = i;
            g[p[i]][gnum[p[i]]].w = d[i];
            gnum[p[i]]++;
        }

        ans=0;

        for(i=2;i<=n;i++)//??¨???????????????????????§?????????????????????
            ans+=d[i];

        for(i=2;i<=n;i++)//degree???1??\?????????????????????????????£?????°??£?????????????????????????????§??????????????????2????????????
            if(gnum[i]!=1 && gnum[p[i]]!=1) ans+=d[i]*2;

        printf("%d\n", ans-solve());
    }
    return 0;
}

void bfs(int s){
    int i, u;
    Edge e;
    for(i=0;i<n;i++) dist[i]=INF;
    qinit();
    enqueue(s);
    dist[s]=0;
    while(!qisEmpty()){
        u=dequeue();
        for(i=0;i<gnum[u];i++){
            e=g[u][i];
            if(dist[e.gt]==INF){
                if(gnum[e.gt]!=1){
                    dist[e.gt]=dist[u]+e.w;
                    enqueue(e.gt);
                }
            }
        }
    }
}

int solve(){
    int i;
    int maxv=0;
    int t=0;
    //??????????§????s????????????????????\???t????±???????
    bfs(2);
    for(i=0;i<n;i++){
        if(dist[i]==INF) continue;
        if(maxv<dist[i]){
            maxv=dist[i]; //?????§????????´??°
            t=i; //?????????????£??????´??°
        }
    }

    //t???????????£??¨???????????\???????????¢maxv????±????????????´??????
    bfs(t);
    maxv=0;
    for(i=0;i<n;i++){
        if(dist[i]==INF) continue;
        if(maxv<dist[i]) maxv=dist[i];
    }
    return maxv;
}