#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int n;
int p[810],d[810];
vector<pii> G[810];
int dp1[810],dp2[810];

void dfs(int v, int pv) {
  vector<pii> A,B;
  for (auto e : G[v]) if (e.first != pv) {
    if (G[e.first].size() == 1) A.push_back(e);
    else B.push_back(e);
  }
  dp1[v] = dp2[v] = 0;
  for (int i = 0; i < A.size(); i++) {
    dp1[v] += A[i].second;
    dp2[v] += A[i].second;
  }
  pii tmp(-1,-1);
  for (int i = 0; i < B.size(); i++) {
    dfs(B[i].first,v);
    dp1[v] += dp1[B[i].first]+3*B[i].second;
    dp2[v] += dp1[B[i].first]+3*B[i].second;
    if (tmp.first < 0 || -dp1[B[i].first]+dp2[B[i].first]-B[i].second < -dp1[tmp.first]+dp2[tmp.first]-tmp.second) {
      tmp = B[i];
    }
  }
  if (!(tmp.first < 0)) {
    dp2[v] += -dp1[tmp.first]+dp2[tmp.first]-tmp.second;
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> n, n) {
    REP(i,n) G[i].clear();
    REP(i,n-1) cin >> p[i], p[i]--;
    REP(i,n-1) cin >> d[i];
    REP(i,n-1) {
      G[p[i]].emplace_back(i+1,d[i]);
      G[i+1].emplace_back(p[i],d[i]);
    }
    int ans = INF;
    REP(i,n) {
      dfs(i,-1);
      CHMIN(ans,dp2[i]);
    }
    cout << ans << endl;
  }

  return 0;
}
