#include <iostream>
#include <vector>
#define REP(i, a, n) for(int i = (a); i < n; i++)
using namespace std;
typedef pair<int, int> pii;

int N, P[800], D[800];
vector<pii> E[800];
bool used[800];


int dfs(int v, int d, int &p, int &m) {
  used[v] = true;
  if(d > m) m = d, p = v;
  int ret = d;
  REP(i, 0, E[v].size()) {
    int u = E[v][i].first;
    if(used[u] || E[u].size() == 1) continue;
    ret = max(ret, dfs(u, d + E[v][i].second, p, m));
  }
  return ret;
}

int radius() {
  int p = 0, m = 0;
  REP(i, 0, N) used[i] = false;
  dfs(0, 0, p, m);
  REP(i, 0, N) used[i] = false;
  int q = 0, n = 0;
  dfs(p, 0, q, n);
  return n;
}

int main(void) {
  while(cin >> N, N) {
    REP(i, 1, N) cin >> P[i];
    REP(i, 1, N) cin >> D[i];
    REP(i, 0, N) E[i].clear();
    REP(i, 1, N) {
      E[i].push_back(pii(P[i] - 1, D[i]));
      E[P[i] - 1].push_back(pii(i, D[i]));
    }

    int r = radius();
    int sum = 0, d = 0;
    REP(i, 1, N) sum += D[i];
    REP(i, 0, N) if(E[i].size() == 1) d += E[i][0].second;

    cout << ((sum - d) * 3 - r + d) << endl;
  }
  return 0;
}