#include <stdio.h>

#define MAX_N  800

int solve(int n, int parent[], int d[])
{
  static int degree[MAX_N];
  static int dist[MAX_N][MAX_N];
  int total;
  int pendant;
  int maxDist;
  int i, s, t;

  /* ?????????????¬???°????¨???? */
  for (i = 0; i < n; i++) { degree[i] = 0; }
  for (i = 1; i < n; i++) {
    degree[parent[i]]++;
    degree[i]++;
  }

  /* ??¨?????????total??¨, ?¬???°1??????????????\?¶????????????????pendant????¨???? */
  total   = 0;
  pendant = 0;
  for (i = 1; i < n; i++) {
    total += d[i];
    if (degree[i] <= 1 || degree[parent[i]] <= 1) {
      pendant += d[i];
    }
  }

  /* i??????j?????§????????¢dist[i][j]????¨???? (i >= j????????????????¨????) */
  maxDist = 0;
  for (s = 0; s < n; s++) {
    int p = parent[s];
    for (t = 0; t < s; t++) {
      /*
       * s??????t?????§????????¢ = s??????p?????§????????¢ + p??????t?????§????????¢.
       * s??????p?????§????????¢ = d[s].
       * p < s??????t < s????????§, dist[p][t]?????????dist[t][p]?????????????¨??????????
       */
      int dpt = (p > t ? dist[p][t] : dist[t][p]); /* p??????t?????§????????¢ */
      dist[s][t] = d[s] + dpt;
      if (degree[s] <= 1 || degree[t] <= 1) continue;
      if (maxDist < dist[s][t]) { /* ?¬???°2??\???????????????????????§?????¢ */
          maxDist = dist[s][t];
      }
    }
  }

  /*
   * (?§??????????????????????)?????????????????????????????? = total (??????????????????????????¢???).
   * ??????????\????????§??????????s, ???????????????t??¨????????¨, 
   *   s, t????¬???°2??\????????????????????????????????°??????.
   *   s??????t?????§?????????????????? (maxDist) ???????????????1?????????.
   *   ?¬???°1??????????????\?¶?????????? (pendant) ????????????????????????.
   *   ????????\????????? (total - pendant - maxDist) ???????????????2?????????(??????).
   */
  return total + maxDist + 2 * (total - pendant - maxDist);
}

int main()
{
  static int parent[MAX_N]; /* parent island */
  static int d     [MAX_N]; /* distance to the parent */
  int n, p, i;
  for (;;) {
    scanf("%d", &n);  /* num of islands */
    if (n == 0) break;
    for (i = 1; i < n; i++) {
      scanf("%d", &p);
      parent[i] = p - 1;  /* parent (0..n-1) of i */
    }
    for (i = 1; i < n; i++) {
      scanf("%d", &d[i]); /* distance to the parent */
    }
    printf("%d\n", solve(n, parent, d));
  }
  return 0;
}