The BFS algorithm is defined as follows.  Consider an undirected graph with vertices numbered from $1$ to $n$. Initialize $q$ as a new queue containing only vertex $1$, mark the vertex $1$ as used.  Extract a vertex $v$ from the head of the queue $q$.  Print the index of vertex $v$.  Iterate in arbitrary order through all such vertices $u$ that $u$ is a neighbor of $v$ and is not marked yet as used. Mark the vertex $u$ as used and insert it into the tail of the queue $q$.  If the queue is not empty, continue from step 2.  Otherwise finish. 

Since the order of choosing neighbors of each vertex can vary, it turns out that there may be multiple sequences which BFS can print.

In this problem you need to check whether a given sequence corresponds to some valid BFS traversal of the given tree starting from vertex $1$. The tree is an undirected graph, such that there is exactly one simple path between any two vertices.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) which denotes the number of nodes in the tree. 

The following $n - 1$ lines describe the edges of the tree. Each of them contains two integers $x$ and $y$ ($1 \le x, y \le n$) — the endpoints of the corresponding edge of the tree. It is guaranteed that the given graph is a tree.

The last line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the sequence to check.


-----Output-----

Print "Yes" (quotes for clarity) if the sequence corresponds to some valid BFS traversal of the given tree and "No" (quotes for clarity) otherwise.

You can print each letter in any case (upper or lower).


-----Examples-----
Input
4
1 2
1 3
2 4
1 2 3 4

Output
Yes
Input
4
1 2
1 3
2 4
1 2 4 3

Output
No


-----Note-----

Both sample tests have the same tree in them.

In this tree, there are two valid BFS orderings:   $1, 2, 3, 4$,  $1, 3, 2, 4$. 

The ordering $1, 2, 4, 3$ doesn't correspond to any valid BFS order.

Difficulty: competition

Starter code:

Solutions:
n = int(input())
graph = [set() for tr in range(n+2)]
i = 1
while i < n:
	x, y = list(map(int, input().split()))
	graph[x].add(y)
	graph[y].add(x)
	i += 1
a = iter(map(int, input().split()))
try:
	assert next(a) == 1
	q = [1]
	for v in q:
		gv = graph[v]
		gv1 = tuple(gv)
		for tr2 in gv1:
			u = next(a)
			assert u in gv
			gv.remove(u)
			graph[u].remove(v)
			q.append(u)
	print("Yes")
except AssertionError:
	print("No")


from collections import deque
n = int(input())
graph = [set() for i in range(n + 1)]
graph[0].add(1)
graph[1].add(0)
for i in range(n - 1):
    x, y = map(int, input().split())
    graph[x].add(y)
    graph[y].add(x)
a = list(map(int, input().split()))
q = deque()
q.append(0)
i = 0
par = [0] * (n + 1)
while len(q):
    v = q.popleft()
    graph[v].discard(par[v])
    l = len(graph[v])
    if graph[v] != set(a[i:i + l]):
        print("No")
        break
    for j in range(i, i + l):
        q.append(a[j])
        par[a[j]] = v
    i += l
else:
    print("Yes")

from collections import deque

def removeUsed(adj, used):
    to_remove = []
    for s in adj:
        if used[s]: to_remove.append(s)
    for s in to_remove:
        adj.remove(s)

def solve(a, s): # a - adjacenct list [[],[]...], seq
    if s[0] != 0: return False
    q = deque()
    q.append(0)
    i, n, cur = 1, len(a), -1
    used = [False]*n
    used[0] = True
    while i < n:
        if cur == -1:
            cur = q.popleft()
            removeUsed(a[cur], used)
        if not a[cur]:
            cur = -1
            continue
        cur_s = s[i]
        i += 1
        if cur_s not in a[cur]:
            return False # not connected
        a[cur].remove(cur_s)
        q.append(cur_s)
        used[cur_s] = True
    return True

n = int(input())
a = [set() for i in range(n)]
for i in range(n-1):
    u, v = list(map(int, input().split()))
    a[u-1].add(v-1)
    a[v-1].add(u-1)
s = [(x-1) for x in map(int, input().split())]
print("Yes" if solve(a, s) else "No")


n=int(input())
dict1={}
for i in range(n-1):
    x,y=list(map(int,input().split()))
    try:
        dict1[y].append(x)
    except:
        KeyError
        dict1[y]=[x]
    try:
        dict1[x].append(y)
    except:
        KeyError
        dict1[x]=[y]    
arr=list(map(int,input().split()))
if(arr[0]!=1):
    print("No")
else:
    j=0
    i=1
    flag=0
    while(i<n and j<n):
        if(arr[j] in dict1[arr[i]]):
            i+=1
        else:
            j+=1
    if(i!=n and j==n):
        print('No')
    else:
        print('Yes')



n=int(input())
dict1={}
for i in range(n-1):
    x,y=list(map(int,input().split()))
    try:
        dict1[y].append(x)
    except:
        KeyError
        dict1[y]=[x]
    try:
        dict1[x].append(y)
    except:
        KeyError
        dict1[x]=[y]    
arr=list(map(int,input().split()))
if(arr[0]!=1):
    print("No")
else:
    j=0
    i=1
    flag=0
    while(i<n and j<n):
        if(arr[j] in dict1[arr[i]]):
            i+=1
        else:
            j+=1
    if(i!=n and j==n):
        print('No')
    else:
        print('Yes')



n = int(input())

d = {}

for i in range(n-1):
	a,b = map(int,input().split())

	try:
		d[a].append(b);
	except:
		d[a] = [b]
	try:
		d[b].append(a);
	except:
		d[b] = [a]

array = list(map(int,input().split()))
flag=0;

if array[0]==1:

	i = 1;
	j = 0;

	while ( j < n and i < n ):
		if ( array[j] in d[array[i]] ):
			i+=1;
		else:
			j+=1;
	if j==n and i!=n:
		flag=1;
else:
	flag=1;

if flag==1:
	print("No")
else:
	print("Yes")

from sys import stdin
from collections import deque
n=int(stdin.readline())
g=dict()
for i in range(n-1):
    a,b=list(map(int,stdin.readline().strip().split()))
    g.setdefault(a, set()).add(b)
    g.setdefault(b, set()).add(a)
a=[int(x) for x in stdin.readline().strip().split()]
ans = True
if n > 1 and a[0] == 1:
    q=deque()
    m=[0]*(n+1)
    q.append(1)
    m[1]=1
    right=1
    while len(q) > 0 and ans:
        first = q.popleft()
        cnt = 0
        for v in g[first]:
            if m[v] == 0:
                cnt += 1
        for i in range(right, right+cnt):
            if m[a[i]] == 0 and a[i] in g[first]:
                m[a[i]] = 1
                q.append(a[i])
            else:
                ans = False
                break
        right += cnt
else:
    ans = a[0] == 1
if ans:
    print("Yes")
else:
    print("No")


from sys import stdin
from collections import deque
n=int(stdin.readline())
g=dict()
for i in range(n-1):
    a,b=list(map(int,stdin.readline().split()))
    g.setdefault(a, set()).add(b)
    g.setdefault(b, set()).add(a)
a=[int(x) for x in stdin.readline().split()]
ans = True
if n > 1 and a[0] == 1:
    q=deque()
    m=[0]*(n+1)
    q.append(1)
    m[1]=1
    right=1
    while len(q) > 0 and ans:
        first = q.popleft()
        cnt = 0
        for v in g[first]:
            if m[v] == 0:
                cnt += 1
        for i in range(right, right+cnt):
            if m[a[i]] == 0 and a[i] in g[first]:
                m[a[i]] = 1
                q.append(a[i])
            else:
                ans = False
                break
        right += cnt
else:
    ans = a[0] == 1
if ans:
    print("Yes")
else:
    print("No")


n=int(input())
dict1={}
for i in range(n-1):
    x,y=list(map(int,input().split()))
    try:
        dict1[y].append(x)
    except:
        KeyError
        dict1[y]=[x]
    try:
        dict1[x].append(y)
    except:
        KeyError
        dict1[x]=[y]    
arr=list(map(int,input().split()))
if(arr[0]!=1):
    print("No")
else:
    j=0
    i=1
    flag=0
    while(i<n and j<n):
        if(arr[j] in dict1[arr[i]]):
            i+=1
        else:
            j+=1
    if(j==n):
        print('No')
    else:
        print('Yes')



from collections import deque

n = int(input())
graph = []
for i in range(n):
    graph.append([])

for i in range(n-1):
    (x, y) = [int(s) for s in input().split(" ")]
    graph[x-1].append(y-1)
    graph[y-1].append(x-1)

seq = [int(s) - 1 for s in input().split(" ")]
visited = [False] * n
levels = [0] * n
positions = [0] * n

for i, item in enumerate(seq):
    positions[item] = i



for item in graph:
    item.sort(key = (lambda x : positions[x]))


# def func(i):
#     if visited[i] == True:
#         return
#     visited[i] = True
#     for item in graph[i]:
#         if not visited[item]:
#             levels[item] = levels[i] + 1
#         func(item)
#
# # func(0)


stack = deque()

ok_route = True
route_pos = 0
stack.append(0)
output_seq = []

while len(stack):
    next_ = stack.popleft()
    visited[next_] = True
    output_seq.append(next_)
    for item in graph[next_]:
        if not visited[item]:
            stack.append(item)

# print(output_seq)

if output_seq == seq:
    print("Yes")
else:
    print("No")








n = int(input())
from collections import defaultdict
l = defaultdict(list)

for _ in range(n-1):
    x,y = map(int,input().split())
    x-=1
    y-=1
    l[x].append(y)
    l[y].append(x)

a = [int(i)-1 for i in input().split(' ')]

vis = [0]*(n+10)

if(a[0]!=0):
    print('No')
    return
x = 1
for i in range(n):
    s1 = set()
    vis[a[i]]=1
    for j in l[a[i]]:
        if(not vis[j]):
            s1.add(j)
    s2 = set()
    for j in range(len(s1)):
        s2.add(a[x])
        x+=1
    if(s1!=s2):
        print('No')
        return
print('Yes')

n = int(input())

d = {}

for i in range(n-1):
    a,b = list(map(int,input().split()))

    try:
        d[a].append(b);
    except:
        d[a] = [b]
    try:
        d[b].append(a);
    except:
        d[b] = [a]

array = list(map(int,input().split()))
flag=0;

if array[0]==1:

    i = 1;
    j = 0;

    while ( j < n and i < n ):
        if ( array[j] in d[array[i]] ):
            i+=1;
        else:
            j+=1;
    if j==n and i!=n:
        flag=1;
else:
    flag=1;

if flag==1:
    print("No")
else:
    print("Yes")


n = int(input())
fst, nxt, lst, des = [0 for i in range(2 * n + 1)], [0 for i in range(2 * n + 1)], [0 for i in range(2 * n + 1)], [0 for i in range(2 * n + 1)]
cnt = 0

def add(u, v) :
	nonlocal cnt
	cnt += 1
	if fst[u] == 0 :
		fst[u] = cnt
	else :
		nxt[lst[u]] = cnt
	lst[u], des[cnt] = cnt, v

for i in range(1, n) : 
	u, v = list(map(int, input().split()))
#	print(u, v)
	add(u, v)
	add(v, u)

a = list(map(int, input().split()))
deep = [0 for i in range(n + 1)]
deep[1] = 1
now, res = 1, 1
Ans = 0

for i in range(0, n) :
	if deep[a[i]] == 0 : 
		Ans = 1
		break
	elif deep[a[i]] < now :
		Ans = 1
		break
	else : 
		b = fst[a[i]]
		res += 1
		while b > 0 :
			if deep[des[b]] == 0 : 
				deep[des[b]] = res
			b = nxt[b]
		now = deep[a[i]]

if Ans == 0 :
	print("Yes")
else :
	print("No")


n = int(input())

d = {}

for i in range(n-1):
    a,b = map(int,input().split())

    try:
        d[a].append(b);
    except:
        d[a] = [b]
    try:
        d[b].append(a);
    except:
        d[b] = [a]

array = list(map(int,input().split()))
flag=0;

if array[0]==1:

    i = 1;
    j = 0;

    while ( j < n and i < n ):
        if ( array[j] in d[array[i]] ):
            i+=1;
        else:
            j+=1;
    if j==n and i!=n:
        flag=1;
else:
    flag=1;

if flag==1:
    print("No")
else:
    print("Yes")

from collections import Counter,defaultdict,deque

read = lambda : list(map(int,input().split()))
getinfo = lambda grid: print(list(map(print,grid)))
p = lambda x: print(x,end=" ")

mod = 10**9 + 7
inf = float('inf')

def solve(a):
    if a[0] != 1: return 'No'
    index = 1
    d1 = defaultdict(set)
    for i in range(n):
        for j in range(index, index+len(d[a[i]])):
            d1[a[i]].add(a[j])
            d[a[j]].discard(a[i])
        if d1[a[i]] != d[a[i]]: return 'No'
        index += len(d[a[i]])
    return 'Yes'

n = int(input())
d = defaultdict(set)
for i in range(n-1):
    a,b = read()
    d[a].add(b)
    d[b].add(a)
a = read()
print(solve(a))


from collections import defaultdict
n = int(input())
d = defaultdict(set)
for i in range(n-1):
    a,b = list(map(int,input().split()))
    d[a].add(b)
    d[b].add(a)

a = list(map(int,input().split()))

def solve(a):
    if a[0] != 1: return 'No'
    i,j = 1,0
    while i<n and j<n:
        if a[j] in d[a[i]]: i += 1
        else: j += 1
    if j == n and i != n: return 'No'
    return 'Yes'

print(solve(a))


MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from collections import defaultdict as dd
n , = I()
d = dd(list)
for i in range(n-1):
	t = I()
	d[t[0]].append(t[1])
	d[t[1]].append(t[0])
l = I()
v = [0]*(n+1)
s = 1
what = 0
v[1] = 1
while what < s:
        a = set()
        i = l[what]
        for j in d[i]:
                if not v[j]:
                        a.add(j)
        b = set()
        for j in range(s,s + len(a)):
                b.add(l[j])
        if a!=b:
                print('No')
                return
        kkk = 0
        for k in a:
            kkk += 1
            v[k] = 1
        s += kkk
        what += 1
if s != n:
    print('No')
    return
print('Yes')


MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from collections import defaultdict as dd
n , = I()
d = dd(list)
for i in range(n-1):
	t = I()
	d[t[0]].append(t[1])
	d[t[1]].append(t[0])
l = I()
v = [0]*(n+1)
s = 1
what = 0
v[1] = 1
while what < s:
        a = set()
        i = l[what]
        for j in d[i]:
                if not v[j]:
                        a.add(j)
        b = set()
        for j in range(s,s + len(a)):
                b.add(l[j])
        if a!=b:
                print('No')
                return
        kkk = 0
        for k in a:
            kkk += 1
            v[k] = 1
        s += kkk
        what += 1
if s != n:
    print('No')
    return
print('Yes')


from queue import Queue
n = int(input())
g = [set() for i in range(n+1)]
for i in range(n-1):
    u, v = list(map(int, input().split()))
    g[u].add(v)
    g[v].add(u)

a = list(map(int, input().split()))
if a[0] != 1:
    print("No")
    return
ptr = 0
i = 1

while i < n:
    par = a[ptr]
    while len(g[par]) != 0:
        if a[i] not in g[par]:
            print("No")
            return
        else:
            g[par].remove(a[i])
            g[a[i]].remove(par)
        i += 1
    ptr += 1
print("Yes")    
                


from collections import deque
n=int(input())
visited=[False for i in range(n+2)]
dp=[-1 for i in range(n+2)]
l=[[] for i in range(n+2)]
for i in range(n-1):
    a,b=list(map(int,input().split()))
    l[a].append(b)
    l[b].append(a)
b=deque(list(map(int,input().split())))
b.popleft()
s=deque([1])
ans="Yes"
visited[1]=True
while len(b)>0 and len(s)>0:
    aux=0
    for i in l[s[0]]:
        if not visited[i]:
            visited[i]=True
            dp[i]=1
            aux+=1
    for i in range(aux):
        x=b.popleft()
        if dp[x]==1:
            s.append(x)
            dp[x]=-1
        else:
            ans="No"
            b=[]
            break
    s.popleft()
print(ans)
            
            
    
            


import sys
from collections import deque
n=int(input())
visited=[False for i in range(n+2)]
dp=[-1 for i in range(n+2)]
l=[[] for i in range(n+2)]
for i in range(n-1):
    a,b=map(int,input().split())
    l[a].append(b)
    l[b].append(a)
b=deque(map(int,input().split()))
b.popleft()
s=deque([1])
visited[1]=True
while len(b)>0 and len(s)>0:
    aux=0
    for i in l[s[0]]:
        if not visited[i]:
            visited[i]=True
            dp[i]=1
            aux+=1
    for i in range(aux):
        x=b.popleft()
        if dp[x]==1:
            s.append(x)
            dp[x]=-1
        else:
            print("No")
            return
    s.popleft()
print("Yes")

import sys
from collections import deque
n=int(input())
visited=[False for i in range(n+1)]
dp=[0 for i in range(n+1)]
l=[[] for i in range(n+1)]
for i in range(n-1):
    a,b=list(map(int,input().split()))
    l[a].append(b)
    l[b].append(a)
b=list(map(int,input().split()))
s=[1]
visited[1]=True
c=1
c1=0
while len(s)!=n :
    aux=0
    for i in l[s[c1]]:
        if not visited[i]:
            visited[i]=True
            dp[i]=1
            aux+=1
    for i in range(c,c+aux):
        if dp[b[i]]==1:
            s.append(b[i])
            dp[b[i]]=0
        else:
            print("No")
            return
    c+=aux
    c1+=1
print("Yes")


import sys
from collections import deque
n=int(input())
visited=[False for i in range(n+1)]
dp=[0 for i in range(n+1)]
l=[[] for i in range(n+1)]
for i in range(n-1):
    a,b=list(map(int,input().split()))
    l[a].append(b)
    l[b].append(a)
b=list(map(int,input().split()))
s=[1]
visited[1]=True
c=1
c1=0
while len(s)!=n :
    aux=0
    for i in l[s[c1]]:
        if not visited[i]:
            visited[i]=True
            dp[i]=1
            aux+=1
    for i in range(c,c+aux):
        if dp[b[i]]==1:
            s.append(b[i])
            dp[b[i]]=0
        else:
            print("No")
            return
    c+=aux
    c1+=1
print("Yes")


import sys
from collections import deque
n=int(input())
visited=[False for i in range(n+1)]
dp=[0 for i in range(n+1)]
l=[[] for i in range(n+1)]
for i in range(n-1):
    a,b=list(map(int,input().split()))
    l[a].append(b)
    l[b].append(a)
b=list(map(int,input().split()))
s=[1]
visited[1]=True
c=1
c1=0
t=True
while len(s)!=n :
    aux=0
    for i in l[s[c1]]:
        if not visited[i]:
            visited[i]=True
            dp[i]=1
            aux+=1
    for i in range(c,c+aux):
        if dp[b[i]]==1:
            s.append(b[i])
            dp[b[i]]=0
        else:
            print("No")
            t=False
            break
    else:
        c+=aux
        c1+=1
        continue
    break
if t:
    print("Yes")