#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
using namespace std;
using llong = long long;

const llong inf = 1ll << 60ll;
llong n;
llong height[805];
llong cost[805][805];
llong dp[805];
llong p[805];
vector<vector<llong>> tree;
llong length[805];
llong leaf_cost;
llong nleaf_cost;

llong calc_height(llong u, llong par) {
    height[u] = -1;
    for (auto v:tree[u]) {
        if (v == par) continue;
        height[u] = max(height[u], calc_height(v, u));
    }

    height[u]++;
    return height[u];
}

void dfs(llong u, llong par, llong c) {
    length[u] = c;
    
    for (auto v:tree[u]) {
        if (v == par) continue;
        if (height[v] == 0) {
            leaf_cost += cost[u][v];
            continue;
        }

        nleaf_cost += cost[u][v];
        dfs(v, u, c + cost[u][v]);
    }
}

void solve() {
    tree.clear();
    tree.resize(n + 1);
    for (int i = 2; i <= n; i++) {
        cin >> p[i];
        tree[p[i]].push_back(i);
        tree[i].push_back(p[i]);
    }
    for (int i = 2; i <= n; i++) {
        llong d;
        cin >> d;
        cost[i][p[i]] = cost[p[i]][i] = d;
    }

    llong ans = inf;
    for (int i = 1; i <= n; i++) {
        nleaf_cost = 0;
        leaf_cost = 0;
        calc_height(i, 0);
        dfs(i, 0, 0);

        for (int j = 1; j <= n; j++) {
            if (height[j] == 0) continue;
            ans = min(ans,
                      leaf_cost + 3 * (nleaf_cost - length[j]) + 2 * length[j]);
        }
    }

    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    while (cin >> n, n) solve();
}

