// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll inf = 5e15;

ll benefit(PLL p) {
    ll a, b;
    tie(a, b) = p;
    return a - b;
}

PLL dfs(ll cur, ll pre, const VV<PLL> &edges, const V<bool> &leaf) {
    V<PLL> ch;
    ll f = 0, s = 0;
    for (auto &&e : edges[cur]) {
        ll nxt, c;
        tie(nxt, c) = e;
        if (nxt == pre) continue;
        if (leaf[nxt]) {
            f += c;
            s += c;
            continue;
        }
        ll a, b;
        tie(a, b) = dfs(nxt, cur, edges, leaf);
        a += 3 * c;
        b += 2 * c;
        ch.emplace_back(a, b);
    }
    sort(ALL(ch), [&](PLL a, PLL b) { return benefit(a) > benefit(b); });
    for (ll i = 0; i < ch.size(); i++) {
        ll a, b;
        tie(a, b) = ch[i];
        f += a;
        s += (i == 0 ? b : a);
    }
    return PLL(f, s);
}

bool solve() {
    ll N;
    cin >> N;
    if (!N) return false;
    VV<PLL> edges(N);
    V<ll> P(N - 1), D(N - 1);
    for (ll &e : P) {
        cin >> e;
        e--;
    }
    for (ll &e : D) cin >> e;
    for (ll i = 1; i < N; i++) {
        ll a = i, b = P[i - 1];
        ll d = D[i - 1];
        edges[a].emplace_back(b, d);
        edges[b].emplace_back(a, d);
    }

    V<bool> leaf(N);
    for (ll i = 0; i < N; i++) leaf[i] = (edges[i].size() == 1);
    ll ans = inf;
    for (ll i = 0; i < N; i++) {
        ll a, b;
        tie(a, b) = dfs(i, -1, edges, leaf);
        DEBUG(make_tuple(a, b));
        chmin(ans, a, b);
    }
    cout << ans << endl;
    return true;
}

int main() {
    while (solve());
    return 0;
}



Measured memory_bytes: 3344