#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<int> p;
    vector<int> ws;
    struct edge {
        int to;
        int w;
    };
    vector<vector<edge>> G;
    vector<vector<edge>> sG;

    void input() {

    }

    // vertex, weight
    pair<int, int> dfs(int v, int p = -1) {
        if (p != -1 && sG[v].size() == 1) return make_pair(v, 0);

        int max_v = -1;
        int max_w = 0;
        for (auto e : sG[v]) {
            if (e.to != p) {
                auto tapi = dfs(e.to, v);
                tapi.second += e.w;
                if (tapi.second > max_w) {
                    max_v = tapi.first;
                    max_w = tapi.second;
                }
            }
        }

        return make_pair(max_v, max_w);
    }

    bool solve() {
        input();
        cin >> N;
        if (N == 0) return false;
        G.resize(N);
        sG.resize(N);
        rep(i, 1, N) {
            int tmp;
            cin >> tmp;
            p.push_back(tmp);
        }
        rep(i, 1, N) {
            int tmp;
            cin >> tmp;
            ws.push_back(tmp);
        }

        for (int i = 0; i + 1 < N; ++i) {
            int a = i + 1;
            int b = p[i];
            int w = ws[i];
            b--;
            G[a].push_back(edge{b, w});
            G[b].push_back(edge{a, w});
        }

        int ans = 0;
        int start = -1;

        for (int i = 0; i < G.size(); ++i) {
            for (auto e : G[i]) {
                int from = i;
                int to = e.to;
                int w = e.w;
                if (from < to) {
                    ans += w;
                    if (G[from].size() != 1 && G[to].size() != 1) {
                        start = from;
                        ans += 2 * w;
                    }
                }

                if (G[from].size() != 1 && G[to].size() != 1) {
                    sG[from].push_back(e);
                }
            }
        }

        if (start != -1) {
            int v = dfs(start).first;
            int chokkei = dfs(v).second;
            ans -= chokkei;
        }
        cout << ans << endl;


        return true;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while (Solve().solve());

    return 0;
}



Measured memory_bytes: 3220