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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INFLL=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct Edge{ int u,v,cost; };
vector<pii> graph[800];

pair<int,int> dfs(int v,int p){
    pair<int,int> res(v,0);
    for(auto &e:graph[v]){
        if(e.first==p) continue;
        if(graph[e.first].size()==1) continue;
        
        auto tmp=dfs(e.first,v);
        tmp.second+=e.second;
        if(res.second<tmp.second) res=tmp;
    }
    
    return res;
}

void solve(){
    int n;
    while(true){
        cin >> n;
        if(!n) break;

        for(auto &v:graph) v.clear();
        
        vector<int> p(n-1),d(n-1);
        rep(i,0,n-1){
            cin >> p[i];
            --p[i]; //辺(i+1,p[i])
        }
        rep(i,0,n-1) cin >> d[i];
        rep(i,0,n-1){
            graph[i+1].push_back(make_pair(p[i],d[i]));
            graph[p[i]].push_back(make_pair(i+1,d[i]));
        }
        
        int ans=0;
        rep(i,0,n-1){
            ans+=d[i]; //撤去にかかる時間
            if(graph[i+1].size()!=1 and graph[p[i]].size()!=1) ans+=d[i]*2; //橋を渡る時間
        }
        
        rep(i,0,n){
            if(graph[i].size()>1){
                int v=dfs(i,-1).first;
                ans-=dfs(v,-1).second; //直径を構成する橋は往復しないので片道分引く
                break;
            }
        }
        
        cout << ans << endl;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}