#include<bits/stdc++.h>
using namespace std;

struct Edge {int from, to, weight;};
typedef vector<vector<Edge>> Graph;

tuple<int, int> farthest(const Graph& tree, const set<int>& vertex, const Edge& pre) {
  tuple<int, int> res(pre.weight, pre.to);
  for(const auto& nex: tree[pre.to]) if(vertex.count(nex.to)) if(nex.to != pre.from)
    res = max(res, farthest(tree, vertex, {nex.from, nex.to, pre.weight + nex.weight}));
  return res;
}

int diameter(const Graph& tree, const set<int>& vertex) {
  int w, v;
  tie(w, v) = farthest(tree, vertex, {-1, *begin(vertex), 0});
  tie(w, v) = farthest(tree, vertex, {v, v, 0});
  return w;
}

int main() {
  int n;
  while(cin >> n, n) {
    vector<int> p(n - 1), d(n - 1);
    for(auto& i: p) cin >> i, --i;
    for(auto& i: d) cin >> i;

    Graph tree(n);
    for(int i = 0; i < n - 1; ++i) {
      tree[p[i]].push_back({p[i], i + 1, d[i]});
      tree[i + 1].push_back({i + 1, p[i], d[i]});
    }

    int answer = 3 * accumulate(begin(d), end(d), 0);
    set<int> vertex;
    for(int i = 0; i < n; ++i) vertex.insert(i);
    for(int i = 0; i < n; ++i) if(tree[i].size() == 1) {
      vertex.erase(i);
      for(const auto& e: tree[i]) answer -= 2 * e.weight;
    }
    answer -= diameter(tree, vertex);
    cout << answer << endl;
  }
}