#include typedef struct List { struct List *next, *prev; int v; long long sum; } list; int main() { int i, N, a[100001], b[100001], par[100001]; scanf("%d", &N); for (i = 2, par[1] = 1; i <= N; i++) scanf("%d", &(par[i])); for (i = 1; i <= N; i++) scanf("%d", &(a[i])); for (i = 1; i <= N; i++) scanf("%d", &(b[i])); int u, w; list head[100001], tail[100001], d[100001], *p, *pp; for (u = 1; u <= N; u++) { head[u].prev = NULL; head[u].next = &(tail[u]); head[u].v = 0; head[u].sum = 1LL << 60; tail[u].prev = &(head[u]); tail[u].next = NULL; tail[u].v = N + 1; tail[u].sum = 0; } for (w = N; w >= 1; w--) { u = par[w]; for (pp = &(head[w]); pp->next->v < a[w]; pp = pp->next); d[w].v = a[w]; d[w].sum = pp->next->sum + b[w]; d[w].prev = pp; d[w].next = pp->next; pp->next->prev = &(d[w]); pp->next = &(d[w]); while (pp->sum <= pp->next->sum) { pp = pp->prev; pp->next->next->prev = pp; pp->next = pp->next->next; } if (w == 1) break; for (p = head[u].next, pp = head[w].next; pp->next != NULL; ) { if (p->v > pp->v) { pp = pp->next; pp->prev->sum += p->sum; if (pp->prev->sum > p->sum) { pp->prev->prev = p->prev; pp->prev->next = p; p->prev->next = pp->prev; p->prev = pp->prev; } } else { while (p->v < pp->v) { p->sum += pp->sum; p = p->next; } } } } printf("%lld\n", head[1].next->sum); fflush(stdout); return 0; }