#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

struct edge {
  ll to, cost;
  edge(ll to, ll cost):to(to), cost(cost){}
};

vector< vector<edge> > G;

P dfs(ll v, ll p)
{
  P ret = P(0, v);
  for(edge e : G[v]) {
    if(e.to == p) continue;
    if(G[e.to].size() == 1) continue;
    P dist = dfs(e.to, v);
    dist.first += e.cost;
    ret = max(ret, dist);
  }
  return ret;
}

ll diameter()
{
  P p = dfs(0, -1);
  P q = dfs(p.second, -1);
  return q.first;
}

int main()
{
  int n;
  while(cin >> n, n) {
    ll p[810], d[810];
    for(int i = 1; i < n; i++) cin >> p[i], p[i]--;
    for(int i = 1; i < n; i++) cin >> d[i];
    ll nodecost = 0LL;
    G.clear(); G.resize(n);
    for(int i = 1; i < n; i++) {
      G[p[i]].push_back(edge(i, d[i]));
      G[i].push_back(edge(p[i], d[i]));
      nodecost += d[i];
    }
    ll leafcost = 0LL;
    for(int i = 0; i < n; i++) {
      if(G[i].size() == 1) leafcost += G[i][0].cost;
    }
    ll diacost = diameter();
    cout << (nodecost - leafcost) * 3 - diacost + leafcost << endl;
  }
  
  return 0;
}