We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i.
To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.
Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to allocate colors and weights so that the following condition is satisfied for all v.
 - The total weight of the vertices with the same color as v among the vertices contained in the subtree whose root is v, is X_v.
Here, the subtree whose root is v is the tree consisting of Vertex v and all of its descendants.
Determine whether it is possible to allocate colors and weights in this way.

-----Constraints-----
 - 1 \leq N \leq 1 000
 - 1 \leq P_i \leq i - 1
 - 0 \leq X_i \leq 5 000

-----Inputs-----
Input is given from Standard Input in the following format:
N
P_2 P_3 ... P_N
X_1 X_2 ... X_N

-----Outputs-----
If it is possible to allocate colors and weights to the vertices so that the condition is satisfied, print POSSIBLE; otherwise, print IMPOSSIBLE.

-----Sample Input-----
3
1 1
4 3 2

-----Sample Output-----
POSSIBLE

For example, the following allocation satisfies the condition:
 - Set the color of Vertex 1 to white and its weight to 2.
 - Set the color of Vertex 2 to black and its weight to 3.
 - Set the color of Vertex 3 to white and its weight to 2.
There are also other possible allocations.

Difficulty: competition

Starter code:

Solutions:
N=int(input())
P=[-1]+[int(i)-1 for i in input().split()]
X=[int(i) for i in input().split()]
Q=[[] for i in range(N)]
for i in range(1,N):
    Q[P[i]].append(i)
dp=[0 for i in range(N)]
INF=10**9+7
def solve(i):
    cur=[INF for j in range(X[i]+1)]
    cur[0]=0
    for j in Q[i]:
        solve(j)
        prv=[k for k in cur]
        cur=[INF for k in range(X[i]+1)]
        for acc in range(len(prv)):
            if prv[acc]<INF:
                if acc+X[j]<=X[i]:
                    cur[acc+X[j]]=min(cur[acc+X[j]],prv[acc]+dp[j])
                if acc+dp[j]<=X[i]:
                    cur[acc+dp[j]]=min(cur[acc+dp[j]],prv[acc]+X[j])
    dp[i]=min(cur)
solve(0)
if dp[0]<INF:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


n = int(input())
P = list(map(int, input().split()))
X = list(map(int, input().split()))

dp = [0]*n
child = [[] for i in range(n)]
for i in range(n-1):
    child[P[i]-1].append(i+1)

for i in range(n-1, -1, -1):
    if not child[i]:
        dp[i] = 0
    else:
        su = 0
        re = 0
        for c in child[i]:
            z = min(X[c], dp[c])
            su += z
        if su > X[i]:
            print("IMPOSSIBLE")
            return
        can = X[i] - su
        ss = set([0])
        for c in child[i]:
            z = min(X[c], dp[c])
            rest = max(X[c], dp[c]) - z
            re += rest
            pp = set(ss)
            for s in ss:
                if s + rest <= can:
                    pp.add(s + rest)
            ss = pp
        dp[i] = su + re - max(ss)
print("POSSIBLE")


# E
N = int(input())
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set) - min_acc

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[i] = c2
    
print(res)


from itertools import chain,product

N = int(input())

P = list(chain((0,), [int(x)-1 for x in input().split()]))
X = list(map(int,input().split()))

L = [list() for _ in range(N)]

debug = [None]*N

for i in reversed(list(range(N))):
  p = P[i]
  l = L[i]

  x = X[i]

  # len(l) < 10のとき全探索、それ以上はDP
  if len(l) < 10:
    m = -1
    for s in product(*l):
      n = sum(s)
      if n <= x:
        m = max(n,m)
    if m == -1:
      print('IMPOSSIBLE')
      return
    m = sum(chain.from_iterable(l)) - m
  else:
    offset = sum(min(t) for t in l)
    x -= offset
    if x < 0:
      print('IMPOSSIBLE')
      return
    dp = [False]*(x+1)
    dp[0] = True
    s = 0
    for a,b in l:
      d = abs(a-b)
      s += d
      for j in reversed(list(range(x-d+1))):
        dp[j+d] = dp[j+d] or dp[j]
    m = x
    while not dp[m]:
      m -= 1
    m = s-m
    m += offset
    x += offset

  debug[i] = (x,m)
  L[p].append((x,m))
  L[i] = None

print('POSSIBLE')



# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = list(map(int, readline().split()))
*p, = list(map(int, readline().split()))
*x, = list(map(int, readline().split()))

dp = [1]*n
z = [0]*n

for i in range(n-1,-1,-1):
    #print(i,x[i],(z[i],(dp[i].bit_length()-1)),bin(dp[i])[2::][::-1])
    if dp[i]==0:
        #print(i)
        #print(dp)
        #print(z)
        print("IMPOSSIBLE")
        return

    y = dp[i].bit_length()-1
    # (z[i]-y,y) を (z[i]-y,x)にするのが最善

    if i == 0:
        #print(dp)
        #print(z)
        print("POSSIBLE")
        return
    else:
        pi = p[i-1]-1
        v = dp[pi]
        dp[pi] = ((v<<x[i]) | (v<<(z[i]-y))) & ((1<<(x[pi]+1))-1)
        z[pi] += x[i]+z[i]-y












def main():
    n=int(input())
    p=list(map(int,input().split()))
    x=list(map(int,input().split()))
    g=[[] for _ in [0]*n]
    [g[j-1].append(i+1) for i,j in enumerate(p)]
    dist=[0]*n
    q=[0]
    while q:
        qq=q.pop()
        for i in g[qq]:
            if i!=0:
                dist[i]=dist[p[i-1]-1]+1
                q.append(i)
    dist=sorted([[-j,i] for i,j in enumerate(dist)])
    dist=[j for i,j in dist]
    memo=[[i,0] for i in x]
    for i in dist:
        if len(g[i])==0:
            continue
        dp=[10003]*(x[i]+1)
        dp[0]=0
        for j in g[i]:
            dp2=[10003]*(x[i]+1)
            for k in range(x[i]-memo[j][0],-1,-1):
                if dp[k]!=10003:
                    dp2[k+memo[j][0]]=min(dp2[k+memo[j][0]],dp[k]+memo[j][1],5001)
            for k in range(x[i]-memo[j][1],-1,-1):
                if dp[k]!=10003:
                    dp2[k+memo[j][1]]=min(dp2[k+memo[j][1]],dp[k]+memo[j][0],5001)
            dp=dp2
        memo[i][1]=min(dp)
        if memo[i][1]==10003:
            print("IMPOSSIBLE")
            break
        #print(dp)
    else:
        print("POSSIBLE")
    #print(memo)

def __starting_point():
    main()
__starting_point()

n = int(input())
p = list(map(int,input().split()))
x = list(map(int,input().split()))
g = [[] for i in range(n)]
for i in range(n-1):
  g[p[i]-1].append(i+1)
kyo = [float("inf")] * n
def dfs(x,y):
  kyo[x] = y
  for i in g[x]:
    dfs(i,y+1)
dfs(0,0)
hukai = []
for i in range(n):
  hukai.append([kyo[i],i])
hukai.sort(key = lambda x:-x[0])
INF = float("inf")
dp = [0]*n
for j,i in hukai:
  if len(g[i]) == 0:
    continue
  tmp = []
  MIN = 0
  MAX= 0
  for k in g[i]:
    tmp.append([dp[k],x[k]])
    MIN += min(dp[k],x[k])
    MAX += max(dp[k],x[k])
  d = {}
  d[MAX] = MIN
  for k in tmp:
    MIN = min(k)
    MAX = max(k)
    co = list(d.keys())
    co.sort(key = lambda x:-x)
    for l in co:
      d[l-MAX+MIN] = min(d.get(l-MAX+MIN, INF),d[l]-MIN+MAX)
  co = list(d.keys())
  co.sort()
  for l in co:
    if d[l] <= x[i]:
      dp[i] = l
      break
  else:
    print("IMPOSSIBLE")
    return
print("POSSIBLE")


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

INF = 2**30
n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = tuple(map(int, input().split()))
D = [-1]*n
def dfs(v):
  if D[v] != -1:
    return D[v]
  l = len(T[v])
  x = X[v]
  dp = [INF]*(x+1)
  dp[0] = 0
  for nv in T[v]:
    k = [INF]*(x+1)
    d = dfs(nv)
    for j in range(x+1):
      if j >= X[nv]:
        k[j] = min(k[j], dp[j-X[nv]]+d)
      if j >= d:
        k[j] = min(k[j], dp[j-d]+X[nv])
    dp = tuple(k)
  res = min(dp)
  D[v] = res
  return res
ans = dfs(0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

def solve():
    from sys import stdin
    f_i = stdin
    
    inf = 5000001
    
    N = int(f_i.readline())
    P = map(int, f_i.readline().split())
    X = tuple(map(int, f_i.readline().split()))
    
    # Create lists of children
    C = [[] for i in range(N)]
    for c, p in enumerate(P, start=1):
        C[p-1].append(c) # Set vertex numbers to 0-based
    
    Y = [inf] * N
    
    # Perform a depth-first search in postorder
    # Execute dp in each sub-tree
    def dfs(v):
        for c in C[v]:
            dfs(c)
        
        X_v = X[v]
        dp1 = [0] * (X_v + 1)
        dp2 = [inf] * (X_v + 1)
        for c in C[v]:
            X_c = X[c]
            Y_c = Y[c]
            for i, b in zip(range(X_c, X_v + 1), dp1):
                if b != inf:
                    dp2[i] = b + Y_c
            for i, w, dp2_i in zip(range(Y_c, X_v + 1), dp1, dp2[Y_c:]):
                tmp = w + X_c
                if tmp < dp2_i:
                    dp2[i] = tmp
            
            dp1 = dp2
            dp2 = [inf] * (X_v + 1)
        
        Y_v = min(dp1)
        Y[v] = Y_v
        return Y_v
    
    ans = dfs(0)
    if ans == inf:
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
    
solve()

# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    P = list(map(int, args[1].split()))
    X = list(map(int, args[2].split()))
    T = [[] for _ in range(n)]
    for i, p in enumerate(P):
        T[p-1].append(i+1)

    seq = []
    stack = [0]
    while stack:
        i = stack.pop()
        seq.append(i)
        for c in T[i]:
            stack.append(c)

    ret = 'POSSIBLE'
    inf = 2**32-1
    Y = [0]*n
    for i in seq[::-1]:
        prev = np.full(X[i]+1, inf, np.int64)
        prev[0] = 0
        for c in T[i]:
            cur = np.full(X[i]+1, inf, np.int64)
            x, y = X[c], Y[c]
            cur = np.minimum(
                np.concatenate((cur[:x], y+prev[:-x if 0 < x else len(prev)])),
                np.concatenate((cur[:y], x+prev[:-y if 0 < y else len(prev)]))
            )
            prev = np.copy(cur)

        y = np.min(prev)
        if y < inf:
            Y[i] = y
        else:
            ret = 'IMPOSSIBLE'
            break

    return ret


def __starting_point():
    print((solve(*(open(0).read().splitlines()))))

__starting_point()

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np

INF = 2**30
n = int(input())
P = tuple(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = tuple(map(int, input().split()))
D = [-1]*n
def dfs(v):
  if D[v] != -1:
    return D[v]
  l = len(T[v])
  x = X[v]
  dp = np.full(x+1, INF, dtype=np.int64)
  dp[0] = 0
  for i, nv in enumerate(T[v]):
    k = np.full(x+1, INF, dtype=np.int64)
    d = dfs(nv)
    if x+1 >= X[nv]:
      np.minimum(k[X[nv]:], dp[:x+1-X[nv]]+d, out=k[X[nv]:])
    if x+1 >= d:
      np.minimum(k[d:], dp[:x+1-d]+X[nv], out=k[d:])
    dp = k.copy()
  res = dp.min()
  D[v] = res
  return res
ans = dfs(0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

import sys
sys.setrecursionlimit(10**7)
def main1(n,p,x):
  ki=[[] for _ in range(n)]
  for i,v in enumerate(p):
    v-=1
    i+=1
    ki[i].append(v)
    ki[v].append(i)
  def dfs(p,v):
    ary=[]
    bs=1
    sa=0
    mina=0
    for nv in ki[v]:
      if nv!=p:
        a,b=dfs(v,nv)
        if a==-1:return -1,-1
        ary.append([a,b])
        nbs=0
        nbs|=bs<<a
        nbs|=bs<<b
        mina+=min(a,b)
        sa+=a+b
        bs=nbs
    if mina>x[v]:return -1,-1
    for j in range(x[v],mina-1,-1):
      if (bs>>j)&1:return x[v],sa-j
    return -1,-1
  a,b=dfs(-1,0)
  if a!=-1:return True
  else:return False

def __starting_point():
  n=int(input())
  p=list(map(int,input().split()))
  x=list(map(int,input().split()))
  ret1=main1(n,p,x)
  print(('POSSIBLE' if ret1 else 'IMPOSSIBLE'))


__starting_point()

#copy for experience
# E
N = int(input())
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set) - min_acc

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[i] = c2
    
print(res)


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    p = LI_()
    x = LI()
    e = collections.defaultdict(list)
    for i in range(n-1):
        e[p[i]].append(i+1)

    def f(i):
        if not e[i]:
            return [0,x[i]]
        a = 0
        xi = x[i]
        xi1 = xi + 1
        tx = [0] * xi1
        tx[0] = 1
        for c in e[i]:
            rc = f(c)
            if not rc:
                return
            a += sum(rc)
            tt = [0] * xi1
            for i in range(xi1):
                if tx[i] == 0:
                    continue
                for c in rc:
                    if i+c < xi1:
                        tt[i+c] = 1
            tx = tt
        for i in range(xi,-1,-1):
            if tx[i] == 1:
                return [xi, a-i]
        return

    if f(0):
        return 'POSSIBLE'

    return 'IMPOSSIBLE'


print((main()))






#!/usr/bin/env python3

def main():
    N = int(input())
    P = list(map(int, input().split()))
    P = [0] + P
    X = list(map(int, input().split()))

    Y = [0] * N
    children = [None] * N

    for i in range(N - 1, 0, -1):
        parent = P[i] - 1
        if children[parent] is None:
            children[parent] = []
        children[parent].append(i)


    for i in range(N - 1, -1, -1):
        if not children[i] is None:
            dp = []
            j_max = len(children[i])
            for j in range(j_max + 1):
                dp.append([0] * 5050)
            dp[0][0] = 1
            x_sum, y_sum = 0, 0
            for j in range(j_max):
                c = children[i][j]
                xc, yc = X[c], Y[c]
                x_sum += xc
                y_sum += yc
                for k in range(X[i] + 1):
                    if xc <= k and dp[j][k - xc] == 1:
                        dp[j + 1][k] = 1
                    if yc <= k and dp[j][k - yc] == 1:
                        dp[j + 1][k] = 1
            f = False
            for k in range(X[i], -1, -1):
                if dp[j_max][k] == 1:
                    Y[i] = x_sum + y_sum - k
                    f = True
                    break
            if not f:
                print('IMPOSSIBLE')
                return

    print('POSSIBLE')


def __starting_point():
    main()


__starting_point()

def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict
import sys
Chi = defaultdict(lambda: [])
F = defaultdict(lambda: [])
N = int(input())
Par = [0] + [int(i)-1 for i in input().split()]
Dis = [-1]*N
X = inpl()
Col = [()]*N
for i in range(N):
    Chi[Par[i]].append(i)
Q = [0]
ctr = 0
while ctr < N:
    st = Q.pop()
    if not Chi[st]:
        continue
    for j in Chi[st]:
        Dis[j] = Dis[st] + 1
        ctr += 1
        Q.append(j)
Chi[0].remove(0)
mD = max(Dis)
for i in range(N):
    F[Dis[i]].append(i)
for d in range(mD, -1, -1):
    for i in F[d]:
        if not Chi[i]:
            Col[i] = (0,X[i])
            continue
        Su = 0
        H = defaultdict(lambda: 0)
        H[0] = 0
        for j in Chi[i]:
            a, b = Col[j]
            Su += a+b
            G = defaultdict(lambda: 0)
            for k in H.keys():
                if a + k <= X[i]:
                    G[a+k] = 1
                if b + k <= X[i]:
                    G[b+k] = 1
            H = G.copy()
            if not H:
                break
        else:
            Col[i] = (Su-max(H), X[i])
            continue
        break
    else:
        continue
    break
else:
    print('POSSIBLE')
    return
print('IMPOSSIBLE')

def main():
    n=int(input())
    p=list(map(int,input().split()))
    x=list(map(int,input().split()))
    
    child=[[] for _ in [0]*n]
    for i,j in enumerate(p):
        child[j-1].append(i+1)
    
    other=[0]*n
    
    for i in range(n-1,-1,-1):
        if child[i]==[]:
            continue
        dp=[-1]*(x[i]+1)
        dp[0]=0
        xx=x[i]
        for j in child[i]:
            dp2=[-1]*(xx+1)
            m=x[j]
            o=other[j]
            for k,l in enumerate(dp):
                if l==-1:
                    continue
                if k+m<=xx:
                    if dp2[k+m]!=-1:
                        dp2[k+m]=min(dp2[k+m],l+o)
                    else:
                        dp2[k+m]=l+o
                if k+o<=xx:
                    if dp2[k+o]!=-1:
                        dp2[k+o]=min(dp2[k+o],l+m)
                    else:
                        dp2[k+o]=l+m
            dp=dp2
        k=[j for j in dp if j!=-1]
        if k!=[]:
            other[i]=min(k)
        else:
            print("IMPOSSIBLE")
            break
    else:
        print("POSSIBLE")

def __starting_point():
	main()

__starting_point()

import sys
input = sys.stdin.readline


N = int(input())
graph = [[] for _ in range(N)]
P = list(map(int, input().split()))
Xs = list(map(int, input().split()))

for i, p in enumerate(P):
    graph[p-1].append(i+1)

stack = [0]
Scores = [[0, 0] for _ in range(N)]
Ind = [0]*N
ok = True
while stack and ok:
    p = stack[-1]
    if Ind[p] == len(graph[p]):
        stack.pop()
        Max = Xs[p]
        dp = [False]*(Max+1)
        dp[0] = True
        S = 0
        for ch in graph[p]:
            a, b = Scores[ch]
            S += a+b
            for x in reversed(range(Max+1)):
                dp[x] = (x >= a and dp[x-a]) or (x >= b and dp[x-b])
        to_ret = -1
        for x in reversed(range(Max+1)):
            if dp[x]:
                to_ret = S - x
                break
        if to_ret == -1:
            ok = False
        else:
            Scores[p] = [Max, to_ret]
    else:
        stack.append(graph[p][Ind[p]])
        Ind[p] += 1

print("POSSIBLE" if ok else "IMPOSSIBLE")

def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    P = list(map(int, input().split()))
    X = list(map(int, input().split()))

    child = [[] for _ in range(N+1)]
    par = [-1] * (N+1)
    for i, p in enumerate(P):
        child[p].append(i+2)
        par[i+2] = p
    child_num = [len(child[i]) for i in range(N+1)]
    st = []
    for i in range(1, N+1):
        if child_num[i] == 0:
            st.append(i)
    dp = [None] * (N+1)
    ok = 1
    while st:
        v = st.pop()
        x = X[v-1]
        if v != 1:
            p = par[v]
            child_num[p] -= 1
            if child_num[p] == 0:
                st.append(p)
        if not child[v]:
            dp[v] = (x, 0)
            continue
        dp2 = [[False] * (x+1) for _ in range(len(child[v])+1)]
        dp2[0][0] = True
        S = 0
        for i, u in enumerate(child[v]):
            a, b = dp[u]
            S += a+b
            for j in range(x+1):
                if dp2[i][j]:
                    if j + a <= x:
                        dp2[i+1][j+a] = True
                    if j+b <= x:
                        dp2[i+1][j+b] = True
        finish = 1
        for j in range(x, -1, -1):
            if dp2[-1][j]:
                dp[v] = (x, S-j)
                finish = 0
                break
        if finish:
            ok = 0
            break

    if ok:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


def __starting_point():
    main()

__starting_point()

n=int(input())
p=list(map(int,input().split()))
x=list(map(int,input().split()))
y=[0]*n
c=[[]for _ in[0]*n]
for i in range(n-1):c[p[i]-1]+=[i+1]
I=float('inf')
for i in range(n-1,-1,-1):
 a=x[i];d=[0]*-~a
 for j in c[i]:
  for k in range(a,-1,-1):b=x[j];e=y[j];f=I if k-b<0else d[k-b]+e;g=I if k-e<0else d[k-e]+b;d[k]=min(f,g,I)
 y[i]=d[a]
print('POSSIBLE'if I>y[0]else'IMPOSSIBLE')

import sys
input = sys.stdin.readline


N = int(input())
graph = [[] for _ in range(N)]
P = list(map(int, input().split()))
Xs = list(map(int, input().split()))

for i, p in enumerate(P):
    graph[p-1].append(i+1)

stack = [0]
Scores = [[0, 0] for _ in range(N)]
Ind = [0]*N
ok = True
while stack and ok:
    p = stack[-1]
    if Ind[p] == len(graph[p]):
        stack.pop()
        Max = Xs[p]
        dp = [False]*(Max+1)
        dp[0] = True
        S = 0
        for ch in graph[p]:
            a, b = Scores[ch]
            S += a+b
            for x in reversed(range(Max+1)):
                dp[x] = (x >= a and dp[x-a]) or (x >= b and dp[x-b])
        to_ret = -1
        for x in reversed(range(Max+1)):
            if dp[x]:
                to_ret = S - x
                break
        if to_ret == -1:
            ok = False
        else:
            Scores[p] = [Max, to_ret]
    else:
        stack.append(graph[p][Ind[p]])
        Ind[p] += 1

print("POSSIBLE" if ok else "IMPOSSIBLE")

from collections import Counter
n = int(input())
p = [0,0]+list(map(int,input().split()))
xls = [0]+list(map(int,input().split()))
dp = [[] for i in range(n+1)]
stack = []
cp = Counter(p)
deg = [cp[i] for i in range(n+1)]
def dp_sol(ls,s):
  l = len(ls)
  mnsm = sum(list(zip(*ls))[0])
  totsm = sum([sum(i) for i in ls])
  if mnsm > s:
    return 10**18
  dp = [[0 for i in range(s+1)] for j in range(l+1)]
  dp[0][0] = 1
  for i in range(1,l+1):
    mn,mx = ls[i-1]
    for j in range(mn,s+1):
      dp[i][j] |= dp[i-1][j-mn]
    for j in range(mx,s+1):
      dp[i][j] |= dp[i-1][j-mx]
  for i in range(s,-1,-1):
    if dp[l][i]:
      return totsm-i
for i in range(1,n+1):
  if cp[i] == 0:
    stack.append(i)
while stack:
  x = stack.pop()
  a = 0
  px = p[x]
  if dp[x]:
    a = dp_sol(dp[x],xls[x])
    if a == 10**18:
      print("IMPOSSIBLE")
      return
  if a < xls[x]:
    dp[px].append((a,xls[x]))
  else:
    dp[px].append((xls[x],a))
  deg[px] -= 1
  if deg[px] == 0:
    stack.append(px)
print("POSSIBLE")

n=int(input())
p,x=[list(map(int,input().split())) for _ in [0]*2]
g=[[] for _ in [0]*n]
[g[j-1].append(i+1) for i,j in enumerate(p)]
d=[0]*n
q=[0]
while q:
 r=q.pop()
 for i in g[r]:
  if i!=0:
   d[i]=d[p[i-1]-1]+1
   q.append(i)
d=sorted([[-j,i] for i,j in enumerate(d)])
m=[[i,0] for i in x]
a,b=10003,5001
for _,i in d:
 y=x[i]+1
 e=[a]*y
 e[0]=0
 for j in g[i]:
  f=[a]*y
  p,q=m[j]
  for k in range(y-p):
   if e[k]!=a:f[k+p]=min(f[k+p],e[k]+q,b)
  for k in range(y-q):
   if e[k]!=a:f[k+q]=min(f[k+q],e[k]+p,b)
  e=f
 m[i][1]=min(e)
 if min(e)==a:
  print("IMPOSSIBLE")
  break
else:print("POSSIBLE")

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np

INF = 2**30
n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = list(map(int, input().split()))
D = [-1]*n
def dfs(v):
  if D[v] != -1:
    return D[v]
  l = len(T[v])
  x = X[v]
  dp = np.full(x+1, INF, dtype=np.int64)
  dp[0] = 0
  for i, nv in enumerate(T[v]):
    k = np.full(x+1, INF, dtype=np.int64)
    if x+1 >= X[nv]:
      np.minimum(k[X[nv]:], dp[:x+1-X[nv]]+dfs(nv), out=k[X[nv]:])
    if x+1 >= dfs(nv):
      np.minimum(k[dfs(nv):], dp[:x+1-dfs(nv)]+X[nv], out=k[dfs(nv):])
    dp = k.copy()
  res = dp.min()
  D[v] = res
  return res
ans = dfs(0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

n = int(input())
p = [0,0] + list(map(int,input().split()))
x = [0] + list(map(int,input().split()))

child = [[] for _ in range(n+1)]
for i,pi in enumerate(p[2:],2):
    child[pi].append(i)

tp = []
stack = [1]
while(stack):
    i = stack.pop()
    tp.append(i)
    for ci in child[i]:
        stack.append(ci)

tp = tp[::-1]

cost = [[-1,-1] for _ in range(n+1)]
for i in tp:
    tot = 0
    mins = 0
    dif = []
    for ci in child[i]:
        a,b = cost[ci]
        if(a > b):
            a,b = b,a
        mins += a
        tot += a+b
        dif.append(b-a)

    if( mins > x[i]):
        print('IMPOSSIBLE')
        return

    dp = 1
    dp_max = (1<<(x[i] - mins+1)) - 1
    for di in dif:
        dp = (dp|(dp<<di))&dp_max

    max_dif = -1
    while(dp>0):
        dp//=2
        max_dif += 1

    a = x[i]
    b = tot - mins - max_dif
    cost[i] = [a,b]

print('POSSIBLE')


from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
P = list(map(int, input().split()))
X = list(map(int, input().split()))

tree = [[] for i in range(N)]


for i in range(N - 1):
	tree[P[i] - 1].append(i + 1)

sum_list = [0]*N
que = deque([0])
que2 = deque([0])
while len(que) > 0:
	node = que.popleft()
	if len(tree[node]) > 0:
		for edge in tree[node]:
			que.append(edge)
			que2.append(edge)

for i in range(N - 1, -1, -1):
	node = que2[i]
	if len(tree[node]) > 0:
		for edge in tree[node]:
			sum_list[node] += sum_list[edge]
	sum_list[node] += X[node]

score = [[0,0] for i in range(N)]
for i in range(N - 1, -1, -1):
	node = que2[i]
	if len(tree[node]) == 0:
		score[node] = [X[node], 0]
	else:
		rest = X[node]
		dp = [[0 for i in range(len(tree[node]) + 1)] for j in range(rest + 1)]
		dp[0][0] = 1
		for x in range(rest + 1):
			for n in range(1, len(tree[node]) + 1):
				dp[x][n] = 0
				if x - score[tree[node][n-1]][0] >= 0:
					dp[x][n] = dp[x - score[tree[node][n-1]][0]][n - 1]
				if x - score[tree[node][n-1]][1] >= 0:
					dp[x][n] = dp[x][n] | dp[x - score[tree[node][n-1]][1]][n - 1]
		judge = 0
		#print(dp)
		for x in range(rest, -1, -1):
			#print(x, len(tree[node]))
			if dp[x][len(tree[node])] == 1:
				judge = 1
				under_sum = 0
				for n in range(len(tree[node])):
					under_sum += sum(score[tree[node][n]])
				under_sum += rest - x
				under_sum -= X[node]
				score[node] = [X[node], under_sum]
				break
		if judge == 0:
			print("IMPOSSIBLE")
			return
print("POSSIBLE")

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np

INF = 2**30
n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = list(map(int, input().split()))
D = [[-1]*n for _ in range(2)]
def dfs(color, v):
  if D[color][v] != -1:
    return D[color][v]
  l = len(T[v])
  x = X[v]
  dp = np.full(x+1, INF, dtype=np.int64)
  dp[0] = 0
  for i, nv in enumerate(T[v]):
    k = np.full(x+1, INF, dtype=np.int64)
    if x+1 >= X[nv]:
      np.minimum(k[X[nv]:], dp[:x+1-X[nv]]+dfs(color, nv), out=k[X[nv]:])
    if x+1 >= dfs(color^1, nv):
      np.minimum(k[dfs(color^1, nv):], dp[:x+1-dfs(color^1, nv)]+X[nv], out=k[dfs(color^1, nv):])
    dp = k.copy()
  res = dp.min()
  D[color][v] = res
  return res
ans = dfs(0, 0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

import sys
from collections import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

n = int(input())
pp = LI()
xx = LI()
to = defaultdict(list)
ww = [[-1, -1] for _ in range(n)]

def dfs(u=0):
    if not len(to[u]):
        ww[u] = [xx[u], 0]
        return True
    ret_ww = set([0])
    uw = xx[u]
    sum_ret_w = 0
    for cu in to[u]:
        if not dfs(cu): return False
        new_ret_ww = set()
        for cuw in ww[cu]:
            sum_ret_w += cuw
            for ret_w in ret_ww:
                new_ret_w = ret_w + cuw
                if new_ret_w <= uw: new_ret_ww.add(new_ret_w)
        ret_ww = new_ret_ww
    if not ret_ww: return False
    ww[u] = [uw, sum_ret_w - max(ret_ww)]
    return True

def main():
    for u, p in enumerate(pp, 1):
        to[p - 1].append(u)
    # print(to)
    if dfs():
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    # print(ww)

main()


import sys
input = sys.stdin.readline
import numpy as np
sys.setrecursionlimit(10**6)

N = int(input())
graph = [[] for _ in range(N+1)] # parent to child
for i,p in enumerate(input().split(),2):
    graph[int(p)].append(i)
X = [None] + [int(x) for x in input().split()]

def dfs(v):
    # None または 白、黒の2つ組を返す
    child = []
    for w in graph[v]:
        c = dfs(w)
        if c is None:
            return None
        child.append(c)
    S = sum(a+b for a,b in child)
    x = X[v]
    dp = np.zeros(x+1, dtype=np.bool) # 2択の繰り返しで作れる和
    dp[0] = 1
    for a,b in child:
        prev = dp
        dp = np.zeros_like(prev)
        if a <= x:
            dp[a:] = prev[:x+1-a]
        if b <= x:
            dp[b:] |= prev[:x+1-b]
    nz = np.nonzero(dp)[0]
    if len(nz) == 0:
        return None
    return x, S - nz[-1]

answer = 'POSSIBLE' if dfs(1) is not None else 'IMPOSSIBLE'
print(answer)



N = int(input())
P = [0] + list(map(int, input().split()))
X = list(map(int, input().split()))

V = [[0, {0: True}, 0, 0] for i in range(N)]  # 子の数，可能な子孫の重み，白黒の総和，裏の値
for i in range(1, N):
    V[P[i]-1][0] += 1

from collections import deque
Open = deque()
for i, v in enumerate(V):
    if v[0]==0:
        Open.append(i)
#print(Open)
while len(Open)!=0:
    iv = Open.popleft()
    v = V[iv]
    if len(v[1]) == 0:
        print("IMPOSSIBLE")
        return
    v[3] = v[2] - max(v[1].keys())

    u = P[iv]-1
    if u==-1:
        print("POSSIBLE")
        #print(V)
        return
    V[u][0] -= 1
    if V[u][0] == 0:
        Open.append(u)
    V[u][2] += X[iv] + v[3]
    newdic = {}
    for key, val in list(V[u][1].items()):
        if key+X[iv] <= X[u]:
            newdic[key+X[iv]] = True
        if key+v[3] <= X[u]:
            newdic[key+v[3]] = True
    V[u][1] = newdic

raise ValueError


n = int(input())
P = list(map(int, input().split()))
X = list(map(int, input().split()))

dp = [0] * n
child = [[] for i in range(n)]
for i in range(n-1):
    child[P[i] - 1].append(i + 1)

for i in range(n-1, -1, -1):
    if not child[i]:
        dp[i] = 0
    else:
        child_sum_min = 0
        child_sum_rest = 0
        change_candidate = set([0]) #色を変更した場合に生じる差分を管理する
        for c in child[i]:
            z = min(X[c], dp[c])
            child_sum_min += z
        if child_sum_min > X[i]:
            print('IMPOSSIBLE')
            return
        change_space = X[i] - child_sum_min
        for c in child[i]:
            z = min(X[c], dp[c])
            rest = max(X[c], dp[c]) - z
            child_sum_rest += rest
            tmp = set(change_candidate)
            for num in change_candidate:
                if num + rest <= change_space:
                    tmp.add(num + rest)
            change_candidate = tmp
        dp[i] = child_sum_min + child_sum_rest - max(change_candidate)

print('POSSIBLE')

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

INF = 2**30
n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = tuple(map(int, input().split()))
D = [-1]*n
def dfs(v):
  if D[v] != -1:
    return D[v]
  l = len(T[v])
  x = X[v]
  dp = [INF]*(x+1)
  dp[0] = 0
  for nv in T[v]:
    k = [INF]*(x+1)
    d = dfs(nv)
    for j in range(x+1):
      if j >= X[nv]:
        k[j] = min(k[j], dp[j-X[nv]]+d)
      if j >= d:
        k[j] = min(k[j], dp[j-d]+X[nv])
    dp = tuple(k)
  res = min(dp)
  D[v] = res
  return res
ans = dfs(0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

# coding: utf-8
from collections import defaultdict, deque

import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    P = list(map(int, args[1].split()))
    X = list(map(int, args[2].split()))

    T = defaultdict(set)
    for i, p in enumerate(P):
        T[p-1].add(i+1)

    stack = []
    Q = deque()
    Q.append(0)
    while Q:
        i = Q.popleft()
        stack.append(i)
        for c in T[i]:
            Q.append(c)

    ret = 'POSSIBLE'
    inf = 2**32-1
    Y = [0]*n
    for i in stack[::-1]:
        prev = np.full(X[i]+1, inf, np.int64)
        prev[0] = 0
        x_acc, y_acc = 0, 0
        for c in T[i]:
            cur = np.full(X[i]+1, inf, np.int64)
            x, y = X[c], Y[c]
            x_acc += x
            y_acc += y
            cur[x:] = np.minimum(cur[x:], y+prev[:-x if 0 < x else len(prev)])
            cur[y:] = np.minimum(cur[y:], x+prev[:-y if 0 < y else len(prev)])
            prev = np.copy(cur)

        y = np.min(prev)
        if y < inf:
            Y[i] = y
        else:
            ret = 'IMPOSSIBLE'
            break

    return ret


def __starting_point():
    print((solve(*(open(0).read().splitlines()))))

__starting_point()