#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

void dfs(int id,int pre,vector<vector<pair<int,int> > > &g,vector<bool>&flag,vector<int>&dst){
    for(auto x:g[id]){
        int s = x.first;
        int d = x.second;
        if(flag[s])continue;
        if(s!=pre){
            dst[s] = dst[id] + d;
            dfs(s,id,g,flag,dst);
        }
    }
}

int main(){
    int n;
    while(cin>> n&&n!=0){
        vector<vector<pair<int,int> > > g(n);
        vector<bool>flag(n);
        vector<int>dst(n);
        vector<int> p(n-1);
        vector<int> d(n-1);
        rep(i,n-1){
            cin >>p[i];
            p[i]--;
        }
        rep(i,n-1){
            cin >> d[i];
        }
        if(n==2){
            cout << d[0] << endl;
            continue;
        }
        rep(i,n-1){
            g[i+1].push_back(MP(p[i],d[i]));
            g[p[i]].push_back(MP(i+1,d[i]));
        }
        int sm = 0;
        int sm2 = 0;
        rep(i,n){
            if(g[i].size()==1){
                flag[i] = true;
                sm2 += g[i][0].second;
            }else{
                for(auto x:g[i]){
                    sm += x.second;
                }
            }
        }
        sm = (sm-sm2)/2*3;
        sm += sm2;
        int k = -1;
        rep(i,n){
            if(!flag[i]){
                k = i;
            }
        }
        dfs(k,-1,g,flag,dst);
        k = -1;
        int ma = -1;
        for(int i=0;i<n;i++){
            if(ma<dst[i]&&!flag[i]){
                ma = dst[i];
                k = i;
            }
        }
        rep(i,n){
            dst[i] = 0;
        }
        dfs(k,-1,g,flag,dst);
        ma = 0;
        for(int i=0;i<n;i++){
            if(ma<dst[i]){
                ma = dst[i];
                k = i;
            }
        }
        //cerr << sm << " " << ma << endl;
        cout << sm-ma << endl;
    }
    return 0;
}
