#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end()))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename M>
std::vector<typename M::T> re_rooting(const std::vector<std::vector<int>> &adj,
                                      const std::vector<std::vector<typename M::E>> &cost) {
    using T = typename M::T;
    int n = adj.size();
    std::vector<std::vector<T>> dp(n);
    {
        static auto dfs = [&](auto &&self, int cur, int par) -> T {
            dp[cur].resize(adj[cur].size());
            T cum = M::id();
            for (int i = 0; i < adj[cur].size(); i++) {
                if (adj[cur][i] == par) { continue; }
                dp[cur][i] = M::op_TE(self(self, adj[cur][i], cur), cost[cur][i]);
                cum = M::op_TT(cum, dp[cur][i]);
            }
            return cum;
        };
        dfs(dfs, 0, -1);
    }
    std::vector<T> ret(n);
    {
        static auto dfs = [&](auto &&self, int cur, int par, T drop) -> void {
            int m = adj[cur].size();
            std::vector<T> l_cum(m + 1), r_cum(m + 1);
            l_cum[0] = r_cum[m] = M::id();
            for (int i = 0; i < m; i++) {
                if (adj[cur][i] == par) { dp[cur][i] = M::op_TE(drop, cost[cur][i]); }
                l_cum[i + 1] = M::op_TT(l_cum[i], dp[cur][i]);
            }
            for (int i = m - 1; i >= 0; i--) { r_cum[i] = M::op_TT(dp[cur][i], r_cum[i + 1]); }
            for (int i = 0; i < m; i++) {
                if (adj[cur][i] == par) { continue; }
                self(self, adj[cur][i], cur, M::op_TT(l_cum[i], r_cum[i + 1]));
            }
            ret[cur] = l_cum[m];
        };
        dfs(dfs, 0, -1, M::id());
    }
    return ret;
}

struct diameter_rr {
    using T = int;
    using E = int;
    static T id() { return 0; }
    static T op_TT(const T &a, const T &b) { return std::max(a, b); }
    static T op_TE(const T &a, const E &b) { return a + b; }
};

signed main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) { break; }
        vint p(n + 10), d(n + 10);
        vint deg(n + 10);
        for (int i = 2; i <= n; i++) {
            cin >> p[i];
            deg[i]++, deg[p[i]]++;
        }
        int sum_d = 0;
        for (int i = 2; i <= n; i++) {
            cin >> d[i];
            sum_d += d[i];
        }
        map<int, int> idx;
        reps(i, n) {
            int k = idx.size();
            if (deg[i] > 1) { idx[i] = k; }
        }
        vvint adj(idx.size()), cost(idx.size());
        for (int i = 2; i <= n; i++) {
            if (idx.count(i) > 0 && idx.count(p[i]) > 0) {
                adj[idx[i]].push_back(idx[p[i]]), adj[idx[p[i]]].push_back(idx[i]);
                cost[idx[i]].push_back(d[i]), cost[idx[p[i]]].push_back(d[i]);
                sum_d += d[i] * 2;
            }
        }
        vint candiameter = re_rooting<diameter_rr>(adj, cost);
        cout << sum_d - *max_element(all(candiameter)) << endl;
    }
    return 0;
}



Measured memory_bytes: 3468