#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

struct edge{int to, cost;};


vector<edge> G[1000];
pii dfs(int prev, int v){
    pii ret = pii(0,v);
    
    for(auto elm:G[v]){
        if(elm.to==prev)continue;
        if(G[elm.to].size()==1)continue;
        pii tmp = dfs(v, elm.to);
        tmp.first += elm.cost;
        if(tmp.first>ret.first){
            ret = tmp;
        }
    }
    return ret;
}

int main(){
    int n;
    while(cin>>n&&n){
        rep(i,1000)G[i].clear();
        
        vector<int> p(n-1), d(n-1);
        rep(i,n-1)cin>>p[i];
        rep(i,n-1)cin>>d[i];
        
        rep(i,n-1){
            G[p[i]-1].pb(edge{(int)i+1,d[i]});
            G[i+1].pb(edge{p[i]-1,d[i]});
        }
        
        pii d1 = dfs(-1,0);
        pii d2 = dfs(-1,d1.second);
        
        int edge_sum = accumulate(all(d),0);
        int leave_edge_cost_sum = 0;
        rep(i,n){
            if(G[i].size()==1)leave_edge_cost_sum+=G[i][0].cost;
        }
        cout<<edge_sum + 2*(edge_sum-leave_edge_cost_sum) - d2.first<<endl;
    }
}

