#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define INF	(1 << 30)
#define MAX_N	(800)

/* typedef */

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

/* global variables */

static int rtcache[MAX_N][MAX_N], owcache[MAX_N][MAX_N];
static int edges[MAX_N][MAX_N];
static int wghts[MAX_N];
static vi nbrs[MAX_N];
static int n;

/* subroutines */

int roundtrip(int from, int to) {
  // printf("roundtrip %d %d\n", from, to);
  if (rtcache[from][to] >= 0) {
    // printf("  roundtrip %d %d %d\n", from, to, rtcache[from][to]);
    return rtcache[from][to];
  }
  
  int tr = edges[from][to] * 3 + wghts[to];
  for (int i = 0; i < nbrs[to].size(); i++) {
    int v = nbrs[to][i];
    if (v != from)
      tr += roundtrip(to, v);
  }

  // printf("  roundtrip %d %d %d\n", from, to, tr);
  return (rtcache[from][to] = tr);
}

int oneway(int from, int to) {
  // printf("oneway %d %d\n", from, to);
  if (owcache[from][to] >= 0) {
    // printf("  oneway %d %d %d\n", from, to, owcache[from][to]);
    return owcache[from][to];
  }

  int ow = edges[from][to] * 2 + wghts[to];
  if (nbrs[to].size() == 1) {
    // printf("  oneway %d %d %d\n", from, to, ow);
    return (owcache[from][to] = ow);
  }
  
  int min_t = INF;

  for (int i = 0; i < nbrs[to].size(); i++) {
    int v = nbrs[to][i];
    if (v == from) continue;

    int t = ow + oneway(to, v);
    for (int j = 0; j < nbrs[to].size(); j++) {
      int v0 = nbrs[to][j];
      if (v0 != from && v0 != v)
	t += roundtrip(to, v0);
    }
    if (min_t > t) min_t = t;
  }

  // printf("  oneway %d %d %d\n", from, to, min_t);
  return (owcache[from][to] = min_t);
}

/* main */

int main() {
  static int ps[MAX_N], ds[MAX_N];
  static vi terms;
  
  for (;;) {
    cin >> n;
    if (n == 0) break;

    ps[0] = ds[0] = 0;
    for (int i = 1; i < n; i++) cin >> ps[i];
    for (int i = 1; i < n; i++) cin >> ds[i];
    
    for (int i = 0; i < n; i++) {
      fill(edges[i], edges[i] + n, -1);
      nbrs[i].clear();
    }
    fill(wghts, wghts + n, 0);

    for (int i = 1; i < n; i++) {
      int j = ps[i] - 1;
      edges[i][j] = edges[j][i] = ds[i];
      nbrs[i].push_back(j);
      nbrs[j].push_back(i);
    }

    for (int i = 0; i < n; i++) {
      if (nbrs[i].size() == 1 && wghts[i] == 0) {
	int j = nbrs[i].front();
	wghts[j] += edges[i][j];
	nbrs[i].clear();
	for (vi::iterator ni = nbrs[j].begin(); ni != nbrs[j].end(); ni++)
	  if (*ni == i) {
	    nbrs[j].erase(ni);
	    break;
	  }
	edges[i][j] = edges[j][i] = -1;
      }
    }

    terms.clear();
    for (int i = 0; i < n; i++)
      if (nbrs[i].size() == 1) terms.push_back(i);
    int nterms = terms.size();

    if (false) {
      cout << '[';
      for (int i = 0; i < n; i++) {
	cout << '[';
	for (int j = 0; j < n; j++) {
	  if (j > 0) cout << ',';
	  cout << edges[i][j];
	}
	cout << "],";
      }    
      cout << ']' << endl;

      cout << '[';
      for (int i = 0; i < n; i++) {
	cout << '[';
	for (vi::iterator ni = nbrs[i].begin(); ni != nbrs[i].end(); ni++) {
	  if (ni != nbrs[i].begin()) cout << ',';
	  cout << *ni;
	}
	cout << "],";
      }    
      cout << ']' << endl;

      cout << '[';
      for (int i = 0; i < n; i++) {
	if (i > 0) cout << ',';
	cout << wghts[i];
      }    
      cout << ']' << endl;
    }

    int min_t = INF;
  
    if (nterms == 0)
      min_t = *max_element(wghts, wghts + n);
    else {
      for (int i = 0; i < n; i++) {
	fill(rtcache[i], rtcache[i] + n, -1);
	fill(owcache[i], owcache[i] + n, -1);
      }

      for (vi::iterator ti = terms.begin(); ti != terms.end(); ti++) {
	int from = *ti;
	int t = wghts[from] + oneway(from, nbrs[from].front());
	if (min_t > t) min_t = t;
      }
    }

    cout << min_t << endl;
  }

  return 0;
}

Measured memory_bytes: 8868