#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <deque>
#include <utility>
#include <set>
#include <queue>
#include <functional>

#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)
#define RREP(i, n) RFOR(i, 0, n)
#define RFOR(i, a, b) for(int i = int(b) - 1; i >= int(a); --i)

#define CHMAX(a, b) a = (a < b ? b : a)

constexpr double EPS = 1e-7;
constexpr int INF = 1 << 30;

using PAIR = std::pair<int, int>;


signed main() {

	while (true) {
		int n;
		std::cin >> n;
		if (n == 0) break;

		std::vector<int> p(n - 1), d(n - 1);
		REP(i, n - 1) std::cin >> p[i];
		REP(i, n - 1) std::cin >> d[i];

		struct Edge { int to, cost; };
		std::vector<std::vector<Edge>> g(n);
		std::vector<int> in(n, 0);

		int sum = 0, tsum = 0, ttsum = 0;
		REP(i, n - 1) {
			--p[i];
			g[i + 1].emplace_back(Edge{ p[i], d[i] });
			g[p[i]].emplace_back(Edge{ i + 1, d[i] });
			++in[i + 1];
			++in[p[i]];
			sum += d[i];
		}
		tsum = sum;
		REP(i, n) {
			if (in[i] == 1) {
				for (auto& e : g[i]) {
					tsum -= e.cost;
				}
			}
		}

		std::vector<bool> ng(n, false);
		int start = -1;
		REP(i, n) if (in[i] == 1) ng[i] = true, start = i;

		std::vector<int> dist(n, INF);
		dist[start] = 0;
		std::queue<int> que({ start });
		while (!que.empty()) {
			int now = que.front(); que.pop();
			for (auto& e : g[now]) {
				int to = e.to;
				int cost = e.cost;

				if (ng[to]) continue;
				if (dist[to] > dist[now] + cost) {
					dist[to] = dist[now] + cost;
					que.push(to);
				}
			}
		}
		 
		// 直径の端点
		int P, Q;
		int ma = -1;
		REP(i, n) if (!ng[i] && dist[i] > ma) {
			P = i;
			ma = dist[i];
		}

		/////////////////////////////////////////////////////////////////////////
		REP(i, n) dist[i] = INF;
		dist[P] = 0;
		que.push(P);
		while (!que.empty()) {
			int now = que.front(); que.pop();
			for (auto& e : g[now]) {
				int to = e.to;
				int cost = e.cost;

				if (ng[to]) continue;
				if (dist[to] > dist[now] + cost) {
					dist[to] = dist[now] + cost;
					que.push(to);
				}
			}
		}
		ma = -1;
		REP(i, n) if (!ng[i] && dist[i] > ma) {
			Q = i;
			ma = dist[i];
		}
		/////////////////////////////////////////////////////////////////////////

		ttsum = tsum;
		int now = Q;
		while (now != P) {
			for (auto& e : g[now]) {
				if (dist[now] > dist[e.to]) {
					ttsum -= e.cost;
					now = e.to;
					break;
				}
			}
		}

		std::cout << sum + tsum + ttsum << "\n";
	}

	return 0;
}
