#include<bits/stdc++.h>  
using namespace std;  
   
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }  
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }  
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }  
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }  
   
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)  
#define ALL(v) (v).begin(), (v).end()  
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}  
#define fr first  
#define sc second  
   
typedef pair< int , int > Pi;  
typedef pair< int , Pi > Pii;  
   
typedef long long int64;  
const int64 INF = 1LL << 60;  
  
  
//vectorよくなさそう(適当  
  
struct edge{  
  int to, cost;  
};  
  
typedef vector< vector< edge > > Graph;  
  
void add_edge(Graph& info, int u, int v, int cost, bool flag = true){  
  info[u].push_back( (edge){ v, cost});  
  if(flag) info[v].push_back( (edge){ u, cost});  
}  
  
int64 bfs(int idx, Graph& graph){  
  
  typedef pair< int , int > Pi;  
  int64 ans = INF;  
  queue< Pi > que;  
  que.push( Pi( 0, idx));  
  vector< int64 > Flag(graph.size() + 100, 0);  
  int sum = 0;  
  
  while(!que.empty()){  
    Pi p = que.front(); que.pop();  
    Flag[p.second] = p.first; /* 最後は戻らなくて良い */  
    for(int i = 0; i < graph[p.second].size(); i++){  
      edge& e = graph[p.second][i];  
      if(e.to == idx || Flag[e.to] != 0) continue;  
      if(graph[e.to].size() == 1){ /* 消して良い橋やで */  
        sum += e.cost;  
      } else {  
        sum += e.cost * 3; /* 行くコスト + 消すコスト + 戻るコスト(他の橋があるから戻ってくる必要がある)*/  
        que.push( Pi( p.first + e.cost, e.to));  
      }  
    }  
  }  
  for(int i = 0; i < graph.size(); i++){  
    if(i == idx) continue;  
    ans = min( ans, sum - Flag[i]);  
  }  
  return ans;  
}  
  
int main(){  
  int n;  
  while(cin >> n, n){  
  
    Graph info(n + 100);  
    int64 ret = INF;  
  
    vector< int64 > p(n - 1), d(n - 1);  
    cin >> p;  
    cin >> d;  
  
    for(int i = 0; i < n - 1; i++){  
      add_edge( info, i + 1, p[i] - 1, d[i]);   
    }  
  
    for(int i = 0; i < n; i++){  
      ret = min( ret, bfs(i, info));  
    }  
      
    cout << ret << endl;  
  }  
}  