#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

template <class T>
class EdgeBase
{
public:
    int to;
    T cost;
    EdgeBase(){};
    EdgeBase(int to0, T cost0){to = to0; cost = cost0;}
};
typedef EdgeBase<int> Edge;

template<class T>
void shortestPath(const vector<vector<EdgeBase<T> > >& edges, int start, vector<T>& dist)
{
    const T INF = numeric_limits<T>::max();
    const T EPS = static_cast<T>(1.0e-10);

    dist.assign(edges.size(), INF);
    dist[start] = 0;
    priority_queue<pair<T,int>, vector<pair<T,int> >, greater<pair<T,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<T, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first - EPS)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            EdgeBase<T> e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to] - EPS){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> p(n+11);
        for(int i=2; i<=n; ++i)
            cin >> p[i];

        vector<vector<Edge> > edges(n+1);
        int ret = 0;
        for(int i=2; i<=n; ++i){
            int d;
            cin >> d;
            ret += d * 3;
            edges[i].push_back(Edge(p[i], d));
            edges[p[i]].push_back(Edge(i, d));
        }

        for(int i=1; i<=n; ++i){
            if(edges[i].size() == 1)
                ret -= edges[i][0].cost * 2;
        }

        int x = 1;
        while(x <= n && edges[x].size() == 1)
            ++ x;
        if(x <= n){
            vector<int> dist;
            shortestPath(edges, x, dist);
            for(int i=1; i<=n; ++i){
                if(edges[i].size() != 1 && dist[i] > dist[x])
                    x = i;
            }
            shortestPath(edges, x, dist);
            for(int i=1; i<=n; ++i){
                if(edges[i].size() != 1 && dist[i] > dist[x])
                    x = i;
            }
            ret -= dist[x];
        }
        cout << ret << endl;
    }
}