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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    vector<int> p(n),d(n);
    vector<int> jisu(n,0);
    for(int i=1;i<n;i++){
      cin >> p[i];
      p[i]--;
      jisu[i]++,jisu[p[i]]++;
    }
    for(int i=1;i<n;i++){
      cin >> d[i];
    }
    vector<list<pair<int,int>>> e(n);
    int ans=0;
    int sta=0;
    for(int i=1;i<n;i++){
      if(jisu[i]>1&&jisu[p[i]]>1){
        e[i].push_back({p[i],d[i]});
        e[p[i]].push_back({i,d[i]});
        ans+=2*d[i];
        sta=i;
      }
      ans+=d[i];
    }
    vector<int> dist(n,-1);
    dist[sta]=0;
    queue<pair<int,int>> bfs;
    pair<int,int> now;
    bfs.push({sta,0});
    while(!bfs.empty()){
      now=bfs.front();
      bfs.pop();
      for(auto it:e[now.first]){
        if(dist[it.first]==-1){
          dist[it.first]=now.second+it.second;
          bfs.push({it.first,now.second+it.second});
        }
      }
    }
    int ma=0,maid=0;
    for(int i=0;i<n;i++){
      if(ma<dist[i]){
        ma=dist[i],maid=i;
      }
    }
    dist=vector<int>(n,-1);
    dist[maid]=0;
    bfs.push({maid,0});
    while(!bfs.empty()){
      now=bfs.front();
      bfs.pop();
      for(auto it:e[now.first]){
        if(dist[it.first]==-1){
          dist[it.first]=now.second+it.second;
          bfs.push({it.first,now.second+it.second});
        }
      }
    }
    // for(int i=0;i<n;i++) cout << dist[i] << " ";
    // cout << endl;
    ma=0;
    for(int i=0;i<n;i++){
      ma=max(ma,dist[i]);
    }
    cout << ans-ma << endl;
  }
  return 0;
}

