#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
struct Edge {
	int source, target, weight;
	Edge(int source, int target, int weight)
		: source(source), target(target), weight(weight) {}
};
ostream &operator<<(ostream &os, Edge e) {
	os << "(" << e.source << ", " << e.target << ", " << e.weight << ")";
	return os;
}
struct Graph {
	int V;
	vector<vector<Edge>> g;
	Graph(int V) : V(V), g(V) {}
	void add_arc(int s, int t, int w = 1) { g[s].emplace_back(s, t, w); }
	void add_edge(int s, int t, int w = 1) { add_arc(s, t, w); add_arc(t, s, w); }
	void dfs(vector<int> &x, int v, int p, int d) {
		x[v] = d;
		rep(i, 0, g[v].size()) {
			Edge e = g[v][i];
			int u = e.target;
			if (u == p)
				continue;
			dfs(x, u, v, d + e.weight);
		}
	}
	int comp() {
		vector<vector<Edge>>ng(V);
		set<int>st;
		int ret = 0;
		rep(i, 0, g.size()) {
			if (g[i].size() == 1) {
				st.insert(i);
				ret += g[i][0].weight;
			}
		}
		for (auto es : g) {
			for (auto e : es) {
				if (not st.count(e.source) and not st.count(e.target) and e.source<e.target) {
					ng[e.source].eb(e);
					swap(e.source, e.target);
					ng[e.source].eb(e);
				}
			}
		}
		g = ng;
		return ret;

	}
	int diameter() {
		vector<int> d(V);
		rep(i, 0, g.size()) {
			dump(g[i].size());
		}
		rep(i, 0, g.size()) {
			if (g[i].size() > 0) {
				dump(i);
				dfs(d, i, -1, 0);
				break;
			}
		}
		int m = max_element(all(d)) - d.begin();
		dump(m);
		dfs(d, m, -1, 0);
		return *max_element(all(d));
	}
};
signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N;
	while (cin >> N, N) {
		vector<int>p(N); rep(i, 1, N) { cin >> p[i]; }
		vector<int>d(N); rep(i, 1, N) { cin >> d[i]; }
		Graph g(N);
		int sum = 0;
		rep(i, 1, N) {
			g.add_edge(i, p[i] - 1, d[i]);
		}
		int x = g.comp();
		dump(x);
		//dump(g.g);
		for (auto es : g.g) {
			for (auto e : es) {
				sum += e.weight;
			}
		}
		sum /= 2;
		dump(sum);
		int dd = g.diameter();
		dump(dd);
		cout << sum * 3 - dd + x << endl;
	}

	return 0;
}



Measured memory_bytes: 3320