#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct edge{
	int to;
	int from;
	int dis;
};

struct land{
	int edge_n;
	int cost;
	int connectedge;
};

int main() {
	int n;
	while (cin >> n, n){
		vector<edge> e;
		int con[801];
		land l[801] = {0};
		int ans =800*100000;
		for (int i = 2; i <= n; i++){
			cin >> con[i];
		}
		for (int i = 2; i <= n; i++){
			int a;
			cin >> a;
			e.push_back({ con[i], i, a });
			e.push_back({ i, con[i], a });
			l[i].edge_n++;
			l[con[i]].edge_n++;
		}
		for (int i = 1; i <= n; i++){
			if (l[i].edge_n == 1){
				REP(j, e.size()){
					if (e[j].from == i){
						l[e[j].to].cost += e[j].dis;
						l[e[j].to].connectedge++;
					}
				}
			}
		}
		int max=0;
		for (int i = 1; i <= n; i++){
			if (l[i].edge_n!=1&&l[i].edge_n - 1 == l[i].connectedge || l[i].edge_n == l[i].connectedge){
				function<int(int start, int from)> f = [&](int start, int from){
					int ans=0;
					for (int i = 0; i<e.size(); i++){
						if (e[i].from == start&&e[i].to != from&&l[e[i].to].edge_n != 1){
							int a = f(e[i].to, e[i].from) + e[i].dis;
							if (a>ans)ans = a;
						}
					}
					return ans;
				};
				int a = f(i,0);
				if (a > max)max = a;
			}
		}
		int ans2=0;
		for (int i = 0; i <= n; i++){
			ans2 += l[i].cost;
		}
		for (int i = 0; i < e.size(); i++){
			if (e[i].to<e[i].from&&l[e[i].from].edge_n != 1 && l[e[i].to].edge_n != 1)ans2 += e[i].dis * 3;
			
		}
		ans2 -= max;
		cout << ans2 << endl;
	}
}