#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iostream>
using namespace std;
#define max(a,b) a > b ? a : b
vector<pair<int,int> > island[805];
int node_max[805][805]; // 根　各島　　との距離
bool visited[805][805] = {};
int leaf[805] = {};

void dfs(int a,int b){
  int i,j,k;
  visited[a][b] = 1;
  for( i = 0; i < island[b].size(); i++){
    //cout << "island_outloop : " << island[a][i].first << endl;
    if(!visited[a][ island[b][i].first ] && !leaf[a] && !leaf[ island[b][i].first]){
      //cout << "a = " << a << "    " << "b = " << b << endl;
      //cout << "island : " << island[b][i].first << endl;
      //cout << "node_max[a][b] = " << node_max[a][b] << endl;
      node_max[a][ island[b][i].first ] = node_max[a][b] + island[b][i].second;
      //cout << "go to dfs" << endl;
      dfs(a, island[b][i].first);
      //cout << "node_max = "  << node_max[a][island[b][i].first] << endl;
    }
  }
}

int main(){
  int i,j,k,l;
  int n;
  int p[805];
  int d[805];
  int ans,dia; //木の直径
  while(cin >> n && n){
    ans = 0;
    dia = 0;
    for(i = 2;i <= n;i++){
      cin >> p[i];//連結先の島
      //cout << p[i] << endl;
    }
    for(i = 2;i <= n;i++){
      cin >> d[i];
      island[ p[i] ].push_back(make_pair( i, d[i]));
      island[i].push_back(make_pair( p[i], d[i]));
      ans += d[i] * 3;
      //cout << d[i] << endl;
    }
    for(i = 1;i <= n;i++){ // 葉を記録
      if(island[i].size() == 1){
        leaf[i]++;
        ans -= 2* island[i][0].second;
      }
    }
    /*for(i = 1;i <= n; i++){ // 葉を削除
      if(leaf[i]){
        ans -= 2 * island[i][0].second;
        k = island[i][0].first;
        for(j = 0;j <= n;j++){
          if(island[k][j].first == i){
            cout << island[k][j].first << endl;
            break;
          }
        }
        //cout << "before:" << island[k].size() << endl;
        island[k].erase(island[k].begin() + j);
        //cout << "after:" << island[k].size() << endl;
        island[i].pop_back();
      }
    }*/
    for(i = 1;i <= n; i++){
      dfs(i,i);
      for(j = 1;j <= n;j++){
        dia = max(dia,node_max[i][j]);
      }
    }
    //cout << ans << endl;
    //cout << dia << endl;
    cout << ans-dia << endl;
    for(i = 1;i <= n;i++){
      island[i].clear();
      leaf[i] = p[i] = d[i] = 0;
      for(j = 1;j <= n;j++){
        node_max[i][j] = visited[i][j] = 0;
      }
    }
  }
  return 0;
}
