#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
 */
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
//manip
template<class T> bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, T b) {if (a > b) {a = b; return 1;} return 0;}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end())
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
//output
#define out(a) cout << a << endl
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl;
#define outp(v) rep(i, SZ(v)) cout << v[i].F << " " << v[i].S << endl
#define outc(s, t) cout << fixed << setprecision(10) << (double)(t - s) / CLOCKS_PER_SEC << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
//algorithm (have library)
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0, while r < n




int reached[800];
int max_cost, max_cost_from, max_cost_to;
vector<pii> v[800];
void dfs(int id, int w) {
    //cout << id << " " << w << endl;
    rep(i, SZ(v[id])) {
        int f = v[id][i].F;
        int s = v[id][i].S;
        if (SZ(v[v[id][i].F]) == 1) continue;
        if (reached[f]) continue;
        reached[f] = 1;
        w += s;
        if (w > max_cost) {
            max_cost = w;
            max_cost_from = id;
            max_cost_to = f;
        }
        dfs(f, w);
        w -= s;
    }
}



int main() {
    //cast caution
    //look constraints always
    cin.tie(0); ios::sync_with_stdio(false);
    
    
    
    
    
    int n;
    while (cin >> n && n) {
        max_cost = 0;
        rep(i, 800) v[i].clear();
        int p[n], d[n];
        rep(i, n - 1) cin >> p[i];
        int all_cost = 0;
        rep(i, n - 1) {cin >> d[i]; all_cost += d[i];}
        rep(i, n - 1) {
            p[i]--;
            v[i + 1].eb(p[i], d[i]);
            v[p[i]].eb(i + 1, d[i]);
        }
        int leaf_cost = 0;
        rep(s, n) {
            if (SZ(v[s]) == 1) {
                leaf_cost += v[s][0].S;
                continue;
            }
            fill_n(reached, 800, 0);
            reached[s] = 1;
            dfs(s, 0);
        }
        
        //cout << max_cost << endl;
        //cout << leaf_cost << " " << all_cost << " " << max_cost << endl;
        cout << leaf_cost + (all_cost  - leaf_cost - max_cost) * 3 + max_cost * 2 << endl;
    }
    
    
    
    
    
    
}
//cast caution


/*
 最長パスを見つける
 そこは1回しか通らんくていい
 壊す作業はいる
 
 leafにつながる橋は壊すだけ
 渡らん
 
 
 
 */



Measured memory_bytes: 3240