#include <stdio.h>
#include <string.h>

int n;

typedef struct {
  int connected[900];
  int dist[900];
  int cnt;
} Node;

Node nodes[900];

void addEdge(int i, int j, int d) {
  nodes[i].connected[nodes[i].cnt] = j;
  nodes[i].dist[nodes[i].cnt++] = d;

  nodes[j].connected[nodes[j].cnt] = i;
  nodes[j].dist[nodes[j].cnt++] = d;
}

int max = 0;

int dfs(int k, int from, int dist) {
  int i;
  int sum = 0;
  for (i = 0; i < nodes[k].cnt; ++i) {
    if (nodes[k].connected[i] == from) {
      continue;
    }

    int v = nodes[k].connected[i];
    int d = nodes[k].dist[i];
    if (nodes[v].cnt == 1) {
      if (max < dist) {
        max = dist;
      }

      continue;
    }

    sum += dfs(v, k, dist + d) + d;
  }

  return sum;
}

int main(void) {
  int p[900];

  while (scanf("%d", &n), n) {
    memset(nodes, 0, sizeof(nodes));

    int i;
    for (i = 1; i < n; ++i) {
      int t;
      scanf("%d", &t);
      --t;
      p[i] = t;
    }
    int rem = 0;
    for (i = 1; i < n; ++i) {
      int d;
      scanf("%d", &d);

      rem += d;
      addEdge(i, p[i], d);
    }

    int ans = 1e9;
    for (i = 0; i < n; ++i) {
      int first = 0, second = 0;

      int j;
      int sum = 0;
      for (j = 0; j < nodes[i].cnt; ++j) {
        max = 0;
        if (nodes[nodes[i].connected[j]].cnt == 1) {
          continue;
        }

        sum +=
            dfs(nodes[i].connected[j], i, nodes[i].dist[j]) + nodes[i].dist[j];

        if (max > first) {
          second = first;
          first = max;
        } else if (max > second) {
          second = max;
        }
      }

      sum = sum * 2 - first - second + rem;

      if (ans > sum) {
        ans = sum;
      }
    }

    printf("%d\n", ans);
  }
}
