#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
// using Graph = vector<vector<int>>;

struct edge {
    int to, cost;
    edge(){}
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
};
using Graph = vector<vector<edge>>;

// undirected
void addEdge(Graph& G, int x, int y, int c) {
    G[x].emplace_back(y, c);
    G[y].emplace_back(x, c);
}
vi dijkstra(const Graph& G, int s, int g = -1) {
    int n = G.size();
    using State = pair<int, int>;
    priority_queue<State, vector<State>, greater<State>> pq;   // cost, vertex
    vector<int> d(n, inf);
    d[s] = 0;
    pq.push(State(0, s));

    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int v = p.second;
        if (v == g) break;
        if (d[v] < p.first) continue;
        for (const auto& e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(State(d[e.to], e.to));
            }
        }
    }
    return d;
}

void printGraph(const Graph& G) {
    rep(i, G.size()) {
        cout << i << ": ";
        rep(j, G[i].size()) {
            cout << "{" << G[i][j].to << ", " << G[i][j].cost << "}, ";
        }
        cout << endl;
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    while (cin >> n, n) {
        vi p(n), d(n);
        rep2(i, 1, n) {
            cin >> p[i];
            p[i]--;
        }
        rep2(i, 1, n) {
            cin >> d[i];
        }

        Graph G(n);
        vi deg(n);
        rep2(i, 1, n) {
            addEdge(G, i, p[i], d[i]);
            deg[i]++;
            deg[p[i]]++;
        }

        Graph H(n);
        int ans = accumulate(all(d), 0);
        int s = 0;
        rep(i, n) {
            for (auto e : G[i]) {
                if (i < e.to && deg[i] > 1 && deg[e.to] > 1) {
                    addEdge(H, i, e.to, e.cost);
                    ans += 2 * e.cost;
                    s = i;
                }
            }
        }

        auto d1 = dijkstra(H, s);
        int ma_id = -1;
        int ma = -1;
        rep(i, n) {
            if (d1[i] != inf && ma < d1[i]) {
                ma = d1[i];
                ma_id = i;
            }
        }

        auto d2 = dijkstra(H, ma_id);
        int D = -1;
        rep(i, n) {
            if (d2[i] != inf) {
                chmax(D, d2[i]);
            }
        }

        ans -= D;

        cout << ans << endl;
    }
}

Measured memory_bytes: 3264