#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e9
using namespace std;
int n,i,j,a,b,ret,s;
long long p[810],d[810],cnt[810],dist[810];
vector<vector<pair<int,long long> > > c(810);
void init(){
  for(i=0;i<810;i++){
    c[i].clear();
    cnt[i]=0;
  }
}

void bfs(int s){
  queue<int> que;
  que.push(s);
  fill(dist,dist+810,inf);
  dist[s]=0;
  while(que.size()){
    int u = que.front();
    que.pop();
    for(i=0;i<c[u].size();i++){
      int e = c[u][i].first;
      if(dist[e]==inf){
        dist[e]=dist[u]+c[u][i].second;
        que.push(e);
      }
    }
  }
  return;
}

int main(){
  while(cin >> n,n){
    ret = 0;
    init();
    for(i=2;i<=n;i++)cin >> p[i];
    for(i=2;i<=n;i++)cin >> d[i];
    for(i=2;i<=n;i++){
      c[i].push_back(make_pair(p[i],d[i]));
      c[p[i]].push_back(make_pair(i,d[i]));
      cnt[i]++;
      cnt[p[i]]++;
      ret+=d[i]*3;
    }
    for(i=1;i<=n;i++){
      if(cnt[i]==1){
        ret-=2*c[i][0].second;
        int fir=c[i][0].first;
        c[i].clear();
        for(j=0;j<c[fir].size();j++){
          if(c[fir][j].first==i){
            swap(c[fir][j],c[fir].back());
            c[fir].pop_back();
          }
        }
      }
      else s = i;
    }
    bfs(s);
    int u=-1,t=-1;
    for(i=1;i<=n;i++){
      if(dist[i]!=inf && (u==-1 || dist[i]>dist[u]))u = i;
    }
    bfs(u);
    for(i=1;i<=n;i++){
      if(dist[i]!=inf && (t==-1 || dist[i]>dist[t]))t = i;
    }
    ret-=dist[t];
    cout << ret << endl;
  }
  return 0;
}

