#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#define mp make_pair
#define pb push_back
#define INF 100000005
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
typedef pair<int,int> PI;
int n;
bool erased[805];
vector<PI> G[805];
int dist[805];
void dfs(int s){
    rep(i,G[s].size()){
        int to=G[s][i].first;
        if(!erased[to]&&dist[to]>=INF){
            dist[to]=G[s][i].second+dist[s];
            dfs(to);
        }
    }
}


int main(){
    while(1){
        int temp;
        int t[805],ans=0;
        cin>>n;
        if(!n){
            break;
        }
        rep(i,n){
            erased[i]=false;
            G[i].clear();
        }
        rep(i,n-1){
            cin>>t[i];
            t[i]--;
        }
        rep(i,n-1){
            cin>>temp;
            ans+=temp*3;
            G[i+1].pb(mp(t[i],temp));
            G[t[i]].pb(mp(i+1,temp));
        }
        int start = 0;
        rep(i,n){
            if(G[i].size()==1){
                ans-=G[i][0].second*2;
                erased[i]=1;
                if(i==start){
                    start++;
                }
            }
        }
        fill(dist,dist+n,INF);
        dist[start]=0;
        dfs(start);
        rep(i,n){
            if(!erased[i]&&dist[i]>dist[start])start=i;
        }
        fill(dist,dist+n,INF);
        dist[start]=0;
        dfs(start);
        int hoge = 0;
        rep(i,n){
            if(!erased[i]){
                hoge = max(hoge,dist[i]);
            }
        }
        ans -= hoge;
        cout<<ans<<endl;
    }
    return 0;
}