import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct Edge {
    int to, cost;
}

void main() {
    int N;
    Edge[][] G;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        auto ps = readln.chomp.split(" ").map!(to!int).array;
        auto ds = readln.chomp.split(" ").map!(to!int).array;
        G = new Edge[][N + 1];
        foreach (i; 0 .. N - 1) {
            G[i + 2] ~= Edge(ps[i], ds[i]);
            G[ ps[i] ] ~= Edge(i + 2, ds[i]);
        }
        return true;
    }
    void solve() {
        auto memo = new int[][][](2, N + 1, N + 1);
        foreach (i; 0 .. 2) foreach (j; 0 .. N + 1) memo[i][j][] = -1;
        int dfs(int v, int from, bool m) { // m: must return?
            if (G[v].length == 1 && from != 0) return 0;
            if (memo[m][v][from] >= 0) return memo[m][v][from];
            int Ret;
            foreach (e; G[v]) {
                if (e.to == from) continue;
                if (G[e.to].length == 1) {
                    Ret += e.cost;
                }
            }
            if (m) {
                int Add = int.max / 2;
                foreach (e1; G[v]) {
                    if (e1.to == from) continue;
                    if (G[e1.to].length == 1) continue;
                    int Add1 = dfs(e1.to, v, true) + e1.cost * 2;
                    foreach (e2; G[v]) {
                        if (e2.to == from) continue;
                        if (G[e2.to].length == 1) continue;
                        if (e2 == e1) continue;
                        Add1 += dfs(e2.to, v, false) + e2.cost * 3;
                    }
                    Add = min(Add, Add1);
                }
                if (Add == int.max / 2) Add = 0;
                Ret += Add;
            } else {
                foreach (e; G[v]) {
                    if (e.to == from) continue;
                    if (G[e.to].length == 1) continue;
                    Ret += dfs(e.to, v, false) + e.cost * 3;
                }
            }
            //writeln([v, from, m], "->", Ret);
            return memo[m][v][from] = Ret;
        }
        int Ans = int.max / 2;
        foreach (i; 1 .. N + 1) {
            Ans = min(Ans, dfs(i, 0, true));
        }
        writeln(Ans);
    }
    while (input) solve;
}