// Slower C++ solution:
#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 push_back

#define INF (1e9+1)

//#define INF (1LL<<59)



//??¨?????´??? verified AOJ GRL_5_A

#define MAX_V 800



struct edge{ int to,weight; };

pii dfs(int prev, int v, const vector<edge> graph[MAX_V]){   //searching farthest node

    pii r(0,v);

    

    rep(i,graph[v].size()){

        struct edge e = graph[v][i];

        if(e.to == prev) continue;

        pii tmp = dfs(v,e.to,graph);

        tmp.first += e.weight;

        if(r.first < tmp.first) r = tmp;

    }

    return r;

}



int v;



int diameter( const vector<edge> graph[MAX_V] ) {

    int s = 0;

    while(graph[s].size()==0&&s<v)s++;

    if(s==v)return 0;

    pii r = dfs(-1, s, graph);

    pii t = dfs(-1, r.second, graph);

    return t.first; // (r.second, t.second) is farthest pair

}



int main(){

    while(cin>>v&&v){

        int sum=0,lsum=0;

        vector<edge> G[MAX_V];

        vector<int> tmp(v-1);

        rep(i,v-1)cin>>tmp[i];

        rep(i,v-1){

            int c;

            cin>>c;

            G[i+1].pb(edge{tmp[i]-1,c});

            G[tmp[i]-1].pb(edge{(int)i+1,c});

            sum+=c;

        }

        bool used[MAX_V][MAX_V]={};

        rep(i,v){

            if(G[i].size()==1){

                int from = min<int>(i,G[i][0].to);

                int to = max<int>(i,G[i][0].to);

                if(used[from][to])continue;

                used[from][to]=true;

                lsum+=G[i][0].weight;

            }

        }

        

        vector<bool> isLeaf(v,false);

        rep(i,v)if(G[i].size()==1)isLeaf[i]=true;

        

        vector<edge> gr[MAX_V];

        rep(i,v){

            if(isLeaf[i])continue;

            for(auto &e:G[i]){

                if(isLeaf[e.to])continue;

                gr[i].pb(e);

            }

        }



        

//        cout<<sum<<" "<<lsum<<" "<<diameter(gr)<<endl;

        cout<<sum*3 - lsum*2 - diameter(gr)<<endl;

    }

}

// Faster C++ solution for the same problem (measured speedup: 1.7702138269211072x):
#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;

    }

}