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.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Tree algorithms

Graph algorithms

Graph traversal

Shortest paths


Solutions:
n = int(input())
visited = [False] * (n + 1)
l = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	l[a].append(b)
	l[b].append(a)
b = list(map(int, input().split()))
if b[0] != 1:
	print('No')
	exit()
c = 1
aux = len(l[1])
for j in range(n):
	for i in l[b[j]]:
		visited[i] = True
	for i in range(c, c + aux):
		if not visited[b[i]]:
			print('No')
			exit()
	c += aux
	aux = len(l[b[(j + 1) % n]]) - 1
print('Yes')


import sys
from collections import defaultdict, deque
from typing import List, Tuple
input = sys.stdin.readline

def solve(n: int, edges: Tuple[List[int]], traverse: List[int]):
	if traverse[0] != 1:
		return False
	g = defaultdict(set)
	for (a, b) in edges:
		g[a].add(b)
		g[b].add(a)
	q = deque([1])
	head = 1
	for i in range(1, len(traverse)):
		e = traverse[i]
		if e not in g[head]:
			return False
		g[head].discard(e)
		g[e].discard(head)
		q.append(e)
		while q and (not g[head]):
			head = q.popleft()
	return True
n = int(input())
edges = []
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	edges.append((a, b))
traverse = list(map(int, input().split()))
r = solve(n, edges, traverse)
print('Yes' if r else 'No')


n = int(input())
dict = [set() for i in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	dict[a].add(b)
	dict[b].add(a)
seq = list(map(int, input().split()))
i = 1
j = 0
if seq[0] != 1:
	print('No')
	exit()
while i < n and j < n:
	if seq[i] in dict[seq[j]]:
		i += 1
	else:
		j += 1
if i == n:
	print('Yes')
else:
	print('No')


import sys
input = sys.stdin.readline
n = int(input())
btree = [[] for _ in range(n + 1)]
for i in range(n - 1):
	(x, y) = list(map(int, input().split()))
	btree[x].append(y)
	btree[y].append(x)
a = list(map(int, input().split()))
father = [-1] * (n + 1)
visited = [0] * (n + 1)
q = [1]
q_cur = 0
while q_cur < len(q):
	front = q[q_cur]
	q_cur += 1
	nodes = btree[front]
	for node in nodes:
		if not visited[node]:
			father[node] = front
			visited[node] = 1
			q.append(node)
q = [1]
q_cur = 0
cur = 1
visited = [0] * (n + 1)
visited[1] = 1
while q_cur < len(q):
	front = q[q_cur]
	q_cur += 1
	while cur < n and (not visited[a[cur]]) and (father[a[cur]] == front):
		visited[a[cur]] = 1
		q.append(a[cur])
		cur += 1
ok = True
for i in range(1, n + 1):
	if not visited[i]:
		ok = False
		break
if ok:
	print('Yes')
else:
	print('No')


import sys
n = int(input())
visited = [False] * (n + 1)
dp = [0] * (n + 1)
l = [[] for i in range(n + 1)]
for i in range(n - 1):
	aux1 = list(map(int, input().split()))
	l[aux1[1]].append(aux1[0])
	l[aux1[0]].append(aux1[1])
b = list(map(int, input().split()))
visited[1] = True
c = 1
t = True
for j in range(n):
	aux = 0
	for i in l[b[j]]:
		if not visited[i]:
			visited[i] = True
			dp[i] = 1
			aux += 1
	for i in range(c, c + aux):
		if dp[b[i]] == 1:
			dp[b[i]] = 0
		else:
			print('No')
			sys.exit()
	c += aux
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()))
	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')


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def inp():
	return int(stdin.readline())

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	l = [li() for i in range(n - 1)]
	d = {i: [] for i in range(1, n + 1)}
	for i in l:
		(a, b) = i
		d[a].append(b)
		d[b].append(a)
	stack = [1]
	par = [0 for i in range(n + 1)]
	visited = [0 for i in range(n + 1)]
	visited[1] = 1
	while stack:
		a = stack.pop()
		for i in d[a]:
			if not visited[i]:
				visited[i] = 1
				par[i] = a
				stack.append(i)
	l = li()
	if l[0] != 1:
		pr('No')
		return
	x = Counter(par)
	i = 0
	j = 1
	while i < n:
		p = x[l[i]]
		if p == 0:
			i += 1
		else:
			c = 0
			while c < p:
				if par[l[j + c]] != l[i]:
					pr('No')
					return
				c += 1
			j += p
			i += 1
	pr('Yes')
for _ in range(1):
	solve()


from collections import defaultdict, deque
visited = set()
queue = deque()

def bfs(graph, n, node):
	ret = []
	visited.add(node)
	queue.append(node)
	while queue:
		s = queue.popleft()
		ret.append(s)
		for neighbour in graph[s]:
			if neighbour not in visited:
				visited.add(neighbour)
				queue.append(neighbour)
	return ret
visited = set()
n = int(input())
m = n - 1
g = defaultdict(list)
for _ in range(m):
	(x, y) = map(int, input().split())
	g[x].append(y)
	g[y].append(x)
l = list(map(int, input().split()))
o = defaultdict(int)
for i in range(n):
	o[l[i]] = i

def f(i):
	return o[i]
for i in g:
	g[i].sort(key=f)
if bfs(g, n, 1) == l:
	print('Yes')
else:
	print('No')


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 collections, sys
n = int(input())
graph = collections.defaultdict(set)
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].add(b)
	graph[b].add(a)
l = list(map(int, input().split()))
if l[0] != 1:
	print('No')
	sys.exit()
i = 1
j = 0
que = [1]
while i < n and j < n:
	if l[i] in graph[l[j]]:
		i += 1
	else:
		j += 1
if i != n:
	print('No')
else:
	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')


import queue
n = int(input())
tab = [[] for _ in range(n + 1)]
odw = [False for _ in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tab[a].append(b)
	tab[b].append(a)
BFS = list(map(int, input().split()))
if BFS[0] != 1:
	print('No')
	exit()
(p, k) = (1, 0)
while p < n and k < n:
	if BFS[k] in tab[BFS[p]]:
		p += 1
	else:
		k += 1
if p != n and k == n:
	print('No')
else:
	print('Yes')


n = int(input())
d = {}
for i in range(n - 1):
	(x, y) = map(int, input().split())
	try:
		d[x].append(y)
	except:
		d[x] = [y]
	try:
		d[y].append(x)
	except:
		d[y] = [x]
a = list(map(int, input().split()))
if a[0] != 1:
	print('No')
else:
	(indroot, indchild) = (0, 1)
	while indroot < n and indchild < n:
		if a[indroot] in d[a[indchild]]:
			indchild += 1
		else:
			indroot += 1
	if indchild != n and indroot == n:
		print('No')
	else:
		print('Yes')


import io, os
import sys
from functools import lru_cache
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
graph = dd(set)
for i in range(n - 1):
	(u, v) = sp()
	graph[u].add(v)
	graph[v].add(u)
arr = l()
if arr[0] != 1:
	outln('No')
	exit()
d = deque()
d.append(1)
i = 1
while d and i < n:
	temp = d.popleft()
	while arr[i] in graph[temp]:
		d.append(arr[i])
		i += 1
		if i == n:
			break
if i == n:
	outln('Yes')
	exit()
outln('No')


from queue import Queue
n = int(input())
g = [set() for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].add(v)
	g[v].add(u)
a = list(map(int, input().split()))
if a[0] != 1:
	print('No')
	exit()
ptr = 0
i = 1
while i < n:
	par = a[ptr]
	while len(g[par]) != 0:
		if a[i] not in g[par]:
			print('No')
			exit()
		else:
			g[par].remove(a[i])
			g[a[i]].remove(par)
		i += 1
	ptr += 1
print('Yes')


import sys
N = int(sys.stdin.readline())
adj = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = [int(x) for x in sys.stdin.readline().split()]
	adj[a].append(b)
	adj[b].append(a)
array = [int(x) for x in sys.stdin.readline().split()]
arraydummy = [x for x in array]
array = [[array[i], i] for i in range(len(array))]
dict = {}
for i in range(len(array)):
	if array[i][0] not in dict:
		dict[array[i][0]] = array[i][1]
inv_dict = {v: k for (k, v) in dict.items()}
for i in range(N + 1):
	for j in range(len(adj[i])):
		adj[i][j] = dict[adj[i][j]]
	adj[i] = sorted(adj[i])
for i in range(N + 1):
	for j in range(len(adj[i])):
		adj[i][j] = inv_dict[adj[i][j]]
compare = [1]
compareset = set()
compareset.add(1)
for i in range(N):
	for j in range(len(adj[array[i][0]])):
		if adj[array[i][0]][j] not in compareset:
			compare.append(adj[array[i][0]][j])
			compareset.add(adj[array[i][0]][j])
if compare == arraydummy:
	print('Yes')
else:
	print('No')


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque

def dfs():
	stack = [1]
	while stack:
		x = stack.pop()
		for i in tree[x]:
			stack.append(i)
			tree[i].remove(x)
n = int(input())
tree = {i: set() for i in range(1, n + 1)}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tree[a].add(b)
	tree[b].add(a)
dfs()
l = list(map(int, input().split()))
stack = deque()
stack.append(1)
a = 1
flag = 'Yes'
while stack:
	x = stack.popleft()
	s = set()
	for i in range(len(tree[x])):
		s.add(l[a])
		stack.append(l[a])
		a += 1
	if s != tree[x]:
		flag = 'No'
		break
print(flag)


n = int(input())
L = [set() for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	L[a].add(b)
	L[b].add(a)
l = list(map(int, input().split()))
if l[0] != 1:
	print('No')
	exit()
(i, j) = (1, 0)
while i < n and j < n:
	if l[i] in L[l[j]]:
		i += 1
	else:
		j += 1
if i != n:
	print('NO')
else:
	print('YES')


class Node:

	def __init__(self, value):
		self.value = value
		self.connected = set()

	def add_connected(self, value):
		self.connected.add(value)

	def remove_parent(self, value):
		self.connected.remove(value)

def is_valid_DFS(node_map, visit_list, n_node):
	if len(node_map) == 0:
		return True
	if len(node_map) != n_node:
		return False
	if visit_list[0] != 1:
		return False
	queue = [{1}]
	visited = set()
	visit_i = 0
	while len(queue) != 0:
		cur_set = queue[0]
		del queue[0]
		cur_compare = visit_list[visit_i:visit_i + len(cur_set)]
		if cur_set != set(cur_compare):
			return False
		for n in cur_compare:
			if n in visited:
				return False
			else:
				visited.add(n)
		visit_i += len(cur_compare)
		for n in cur_compare:
			child_list = node_map[n]
			for child in child_list:
				node_map[child].remove(n)
			if child_list:
				queue.append(child_list)
	if len(visited) != n_node:
		return False
	else:
		return True
import sys
from collections import defaultdict
node_m = defaultdict(lambda : set())
size = int(sys.stdin.readline())
for _ in range(size - 1):
	(n1, n2) = map(int, sys.stdin.readline().split())
	node_m[n1].add(n2)
	node_m[n2].add(n1)
v_list = list(map(int, sys.stdin.readline().split()))
if is_valid_DFS(node_m, v_list, size):
	print('Yes')
else:
	print('No')


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 os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from collections import deque

def bfs(graph, alpha=0):
	n = len(graph)
	order = []
	q = deque([alpha])
	used = [False] * n
	used[alpha] = True
	(dist, parents) = ([0] * n, [-1] * n)
	while q:
		v = q.popleft()
		order += [v]
		for u in graph[v]:
			if not used[u]:
				used[u] = True
				q.append(u)
				dist[u] = dist[v] + 1
				parents[u] = v
	return (used, dist, parents, order)

def shortest_path(graph, alpha, omega):
	(used, dist, parents) = bfs(graph, alpha)
	if not used[omega]:
		return []
	path = [omega]
	v = omega
	while parents[v] != -1:
		path += [parents[v]]
		v = parents[v]
	return path[::-1]
for _ in range(int(input()) if not True else 1):
	n = int(input())
	graph = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		graph[x] += [y]
		graph[y] += [x]
	a = list(map(int, input().split()))
	di = [0] * (n + 1)
	for i in range(n):
		di[a[i]] = i
	for i in range(1, n + 1):
		b = sorted([di[x] for x in graph[i]])
		graph[i] = [a[x] for x in b]
	(used, dist, parents, order) = bfs(graph, 1)
	print('YES' if a == order else 'NO')


n = int(input())
pc = []
for i in range(n + 1):
	pc.append(set())
for i in range(n - 1):
	(p, c) = map(int, input().split())
	pc[p].add(c)
	pc[c].add(p)
l = list(map(int, input().split()))
(front, back) = (1, 1)
for i in l:
	front = back
	back += len(pc[i])
	if i != 1:
		back -= 1
	if front >= n:
		break
	for j in l[front:back]:
		if j not in pc[i]:
			print('No')
			exit()
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')


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	c = dict(Counter(l))
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	d = defaultdict(lambda : set())
	for i in range(n - 1):
		(x, y) = li()
		d[x].add(y)
		d[y].add(x)
	a = li()
	if a[0] != 1:
		print('No')
		return
	i = 0
	j = 1
	while i < n and j < n:
		if a[j] in d[a[i]]:
			j += 1
		else:
			i += 1
	if j == n:
		print('Yes')
	else:
		print('No')
t = 1
for _ in range(t):
	solve()


from collections import deque
n = int(input())
graph = [set() for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = map(int, input().split())
	graph[x].add(y)
	graph[y].add(x)
l = list(map(int, input().split()))
if l[0] != 1:
	print('No')
	exit()
i = 1
j = 0
while i < n and j < n:
	if l[i] in graph[l[j]]:
		i += 1
	else:
		j += 1
if i == n:
	print('Yes')
else:
	print('No')


from collections import deque

def bfs(n):
	global c, nd, ans, s
	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'
				return
		s.popleft()
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])
ans = 'Yes'
visited[1] = True
bfs(1)
print(ans)


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')


import sys
from collections import defaultdict as ll
l = ll(list)
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) = map(int, input().split())
	l[a].append(b)
	l[b].append(a)
b = list(map(int, input().split()))
visited[1] = True
c = 1
t = True
for j in range(n):
	aux = 0
	for i in l[b[j]]:
		if not visited[i]:
			visited[i] = True
			dp[i] = 1
			aux += 1
	for i in range(c, c + aux):
		if dp[b[i]] == 1:
			dp[b[i]] = 0
		else:
			print('No')
			sys.exit()
	c += aux
print('Yes')


n = int(input())
visited = [False] * (n + 1)
dp = [0] * (n + 1)
l = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	l[a].append(b)
	l[b].append(a)
b = tuple(map(int, input().split()))
visited[1] = True
c = 1
for j in range(n):
	aux = 0
	for i in l[b[j]]:
		if not visited[i]:
			visited[i] = True
			dp[i] = 1
			aux += 1
	for i in range(c, c + aux):
		if dp[b[i]] == 1:
			dp[b[i]] = 0
		else:
			print('No')
			exit()
	c += aux
print('Yes')


import sys
from collections import defaultdict
from collections import deque
input = sys.stdin.readline

def get_adj_mat(src, dst, n):
	matrix = defaultdict(list)
	for (src_i, dst_i) in zip(src, dst):
		matrix[src_i].append(dst_i)
		matrix[dst_i].append(src_i)
	return matrix

def solve(src, dst, n, sequence):
	adj_mat = get_adj_mat(src, dst, n)
	(parent_pos, curr_pos) = (0, 1)
	if sequence[0] != 0:
		return 'No'
	while curr_pos < n:
		par_val = sequence[parent_pos]
		curr_val = sequence[curr_pos]
		if par_val in adj_mat[curr_val]:
			curr_pos += 1
		else:
			parent_pos += 1
		if curr_pos == parent_pos:
			return 'No'
	return 'Yes'
n = int(input())
(src, dst) = ([], [])
for _ in range(n - 1):
	(src_i, dst_i) = [int(val) for val in input().split()]
	(src.append(src_i - 1), dst.append(dst_i - 1))
sequence = [int(val) - 1 for val in input().split()]
print(solve(src, dst, n, sequence))


import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
g = [[] for i in range(n)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	g[u - 1].append(v - 1)
	g[v - 1].append(u - 1)
a = list(map(int, input().split()))
idx = [0] * n
for i in range(n):
	idx[a[i] - 1] = i
for i in range(n):
	g[i].sort(key=lambda x: idx[x])
b = []
dq = deque([[-1, 0]])
b.append(1)
while dq:
	(par, ver) = dq.popleft()
	for to in g[ver]:
		if par != to:
			b.append(to + 1)
			dq.append([ver, to])
if all((a[i] == b[i] for i in range(n))):
	print('Yes')
else:
	print('No')


import sys
from collections import defaultdict
n = int(sys.stdin.readline().lstrip().rstrip())
graph = [set() for i in range(n)]
for i in range(n - 1):
	(u, v) = list(map(int, sys.stdin.readline().lstrip().rstrip().split()))
	graph[u - 1].add(v - 1)
	graph[v - 1].add(u - 1)
bfs = list(map(int, sys.stdin.readline().lstrip().rstrip().split()))
if bfs[0] != 1:
	sys.stdout.write('No' + '\n')
	exit()
cur = 1
prev = 0
while cur < n and prev < n:
	if bfs[cur] - 1 in graph[bfs[prev] - 1]:
		cur += 1
	else:
		prev += 1
if cur != n:
	sys.stdout.write('No' + '\n')
else:
	sys.stdout.write('Yes' + '\n')


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')


def main():
	n = int(input())
	edges = [[] for _ in range(n)]
	for _ in range(n - 1):
		(x, y) = input().split()
		edges[int(x) - 1].append(int(y) - 1)
		edges[int(y) - 1].append(int(x) - 1)
	path = [int(x) - 1 for x in input().split()]
	for edge_list in edges:
		edge_list.sort()

	def bfs():
		queue = [0]
		visited = [False for _ in range(n)]
		queue_head = 0
		visited[0] = True
		if path[0] != 0:
			return False
		while queue_head < len(queue):
			node = queue[queue_head]
			next_nodes = [x for x in edges[node] if not visited[x]]
			len_queue = len(queue)
			len_nodes = len(next_nodes)
			if len_queue + len_nodes > n:
				return False
			if next_nodes != sorted(path[len_queue:len_queue + len_nodes]):
				return False
			for x in path[len_queue:len_queue + len_nodes]:
				queue.append(x)
				visited[x] = True
			queue_head += 1
		return queue_head == n
	print('Yes' if bfs() else 'No')
main()


n = int(input())
dict1 = {}
for i in range(n - 1):
	(x, y) = 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')


import collections

def do():
	nodes = int(input())
	parent = collections.defaultdict(set)
	for _ in range(nodes - 1):
		(x, y) = map(int, input().split(' '))
		parent[y].add(x)
		parent[x].add(y)
	seq = [int(c) for c in input().split(' ')]
	if seq[0] != 1:
		return 'NO'
	last = [seq[0]]
	cur = 0
	i = 1
	while i < len(seq):
		if not last:
			return 'NO'
		level = []
		while i < len(seq):
			if last[cur] in parent[seq[i]]:
				level.append(seq[i])
				i += 1
			else:
				cur += 1
				if cur == len(last):
					last = level
					cur = 0
					break
	return 'YES'
print(do())


from collections import defaultdict
n = int(input())
g = defaultdict(lambda : set())
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].add(v)
	g[v].add(u)
check = list(map(int, input().split()))
if check[0] != 1:
	print('No')
	exit()
(i, j) = (1, 0)
while i < n and j < n:
	if check[i] in g[check[j]]:
		i += 1
	else:
		j += 1
print('Yes' if i == n else 'No')


from collections import Counter, defaultdict, deque
import heapq as hq
from itertools import count, islice
import math
import sys
input = sys.stdin.readline

def BFS(cmap, v):
	order = []
	global visited
	global test
	q = deque([v])
	level = 0
	visited[v] = True
	if test.popleft() != 0:
		return False
	while len(q) != 0:
		for i in range(len(q)):
			vertex = q.popleft()
			for j in range(len(cmap[vertex])):
				u = test.popleft()
				if u not in cmap[vertex]:
					return False
				cmap[u].discard(vertex)
				if not visited[u]:
					visited[u] = True
					q.append(u)
		level += 1
	return True
n = int(input())
conmap = [set() for i in range(n)]
visited = [False] * n
for i in range(n - 1):
	(a, b) = [int(x) - 1 for x in input().split()]
	conmap[a].add(b)
	conmap[b].add(a)
test = deque((int(x) - 1 for x in input().split()))
print('Yes' if BFS(conmap, 0) else 'No')


import collections
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def bfs(graph, root):
	queue = collections.deque([root])
	visited[root] = 1
	while queue:
		vertex = queue.popleft()
		traverse.append(vertex)
		for neighbour in graph[vertex]:
			if visited[neighbour] == 0:
				visited[neighbour] = 1
				queue.append(neighbour)
n = int(input())
graph = dict()
if n == 1:
	print('Yes')
	exit(0)
for i in range(n - 1):
	(frm, to) = map(int, input().split())
	if frm not in graph:
		graph[frm] = [to]
	else:
		graph[frm].append(to)
	if to not in graph:
		graph[to] = [frm]
	else:
		graph[to].append(frm)
sequence = list(map(int, input().split()))
traverse = list()
mapper = [0] * (n + 1)
visited = [0] * (n + 1)
for (idx, v) in enumerate(sequence):
	mapper[v] = idx
for v in graph:
	graph[v].sort(key=lambda x: mapper[x])
bfs(graph, 1)
if sequence == traverse:
	print('Yes')
else:
	print('No')


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))


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')


def Solve(edges, check):
	if check[0] != 1:
		return 'No'
	count = 0
	isVisited = [False] * len(check)
	for i in range(len(check)):
		kids = 0
		isVisited[check[i] - 1] = True
		for kid in edges[check[i]]:
			if not isVisited[kid - 1]:
				kids += 1
		for j in range(count + 1, count + kids + 1):
			if j < len(check):
				if check[j] not in edges[check[i]]:
					return 'No'
		count += kids
	return 'YES'

def main():
	n = int(input())
	edges = []
	for i in range(n + 1):
		edges.append(set())
	for i in range(n - 1):
		(start, end) = map(int, input().split())
		edges[start].add(end)
		edges[end].add(start)
	check = list(map(int, input().split()))
	print(Solve(edges, check))
main()


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	N = getInt()

	def bfs():
		visited = set()
		visited.add(1)
		V[1] = 0
		Parents[1] = 0
		queue = [(1, 0)]
		queue = col.deque(queue)
		while queue:
			(node, level) = queue.popleft()
			for neighbour in graph[node]:
				if neighbour not in visited:
					visited.add(neighbour)
					V[neighbour] = level + 1
					Parents[neighbour] = node
					queue.append((neighbour, level + 1))
		return
	graph = col.defaultdict(set)
	V = col.defaultdict(int)
	Parents = col.defaultdict(int)
	for n in range(N - 1):
		(u, v) = getInts()
		graph[u].add(v)
		graph[v].add(u)
	bfs()
	A = getInts()
	prev = -1
	prev_node = 0
	a_prev = 0
	pid = col.defaultdict(int)
	j = 1
	for a in A:
		pid[a] = j
		level = V[a]
		if level < prev:
			return 'No'
		if level > 0 and pid[Parents[a]] < pid[Parents[a_prev]]:
			return 'No'
		prev = level
		a_prev = a
		j += 1
	return 'Yes'
print(solve())


import sys
input = sys.stdin.readline
from collections import deque, defaultdict

def bfs():
	q = deque([0])
	visited = [False] * n
	visited[0] = True
	while q:
		v = q.popleft()
		check.append(v)
		l = []
		for nv in G[v]:
			if not visited[nv]:
				l.append((nv, d[nv]))
		l.sort(key=lambda k: k[1])
		for (nv, _) in l:
			visited[nv] = True
			q.append(nv)
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	G[x - 1].append(y - 1)
	G[y - 1].append(x - 1)
a = list(map(int, input().split()))
a = list(map(lambda x: x - 1, a))
d = defaultdict(int)
for i in range(n):
	d[a[i]] = i
check = []
bfs()
if a == check:
	print('Yes')
else:
	print('No')


import sys
from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 8
n = int(ri())
g = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = Ri()
	g[a].append(b)
	g[b].append(a)
lis = Ri()
dic = {}
for i in range(len(lis)):
	dic[lis[i]] = i
for i in range(1, n + 1):
	g[i].sort(key=lambda x: dic[x])
vis = [False] * (n + 1)
flag = [False] * (n + 1)
tflag = True
q = deque()
q.append(1)
point = 0
while len(q) > 0:
	s = [i for i in q]
	ite = 0
	for i in range(point, point + len(s)):
		if lis[i] != s[ite]:
			tflag = False
			break
		ite += 1
	point = point + len(s)
	if not tflag:
		break
	tq = deque()
	while len(q) > 0:
		node = q.popleft()
		vis[node] = True
		for child in g[node]:
			if not vis[child]:
				tq.append(child)
	q = tq
if tflag:
	Yes()
else:
	No()


from sys import stdin
from collections import deque
n = int(input())
visited = [False] * (n + 1)
l = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, stdin.readline().strip().split())
	l[a].append(b)
	l[b].append(a)
b = list(map(int, stdin.readline().strip().split()))
if b[0] != 1:
	print('No')
	exit()
c = 1
aux = len(l[1])
for j in range(n):
	for i in l[b[j]]:
		visited[i] = True
	for i in range(c, c + aux):
		if not visited[b[i]]:
			print('No')
			exit()
	c += aux
	aux = len(l[b[(j + 1) % n]]) - 1
print('Yes')


from sys import stdin, stdout
from collections import defaultdict, Counter, deque
from bisect import bisect, bisect_left
import math
from itertools import permutations
import queue
I = stdin.readline
n = int(I())
v = defaultdict(lambda : set())
for _ in range(n - 1):
	(a, b) = map(int, I().split())
	v[a].add(b)
	v[b].add(a)
arr = [int(x) for x in I().split()]
if arr[0] != 1:
	print('No')
else:
	i = 1
	j = 0
	while i < n and j < n:
		if arr[i] in v[arr[j]]:
			i += 1
		else:
			j += 1
	if i == n:
		print('Yes')
	else:
		print('No')


n = int(input())
d = {}
for i in range(n - 1):
	(u, v) = map(int, input().split())
	try:
		d[u].append(v)
	except:
		d[u] = [v]
	try:
		d[v].append(u)
	except:
		d[v] = [u]
l = list(map(int, input().split()))
f = 0
i = 0
j = 1
while i < n and j < n:
	if l[i] not in d[l[j]]:
		i = i + 1
	else:
		j = j + 1
if j != n or l[0] != 1:
	print('No')
else:
	print('Yes')


import sys
from collections import defaultdict

def out(s):
	return sys.stdout.write(s)
n = int(sys.stdin.readline())
dic = defaultdict(set)
for i in range(n - 1):
	(a, b) = map(int, sys.stdin.readline().split())
	dic[a].add(b)
	dic[b].add(a)
c = list(map(int, sys.stdin.readline().split()))
if c[0] != 1:
	out('No')
else:
	i = 1
	j = 0
	while i < n and j < n:
		if c[i] not in dic[c[j]]:
			j += 1
		else:
			i += 1
	if i == n:
		out('Yes')
	else:
		out('No')


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		graph = [[] for i in range(n + 1)]
		vis = [0] * (n + 1)
		dist = [0] * (n + 1)
		for i in range(n - 1):
			(a, b) = ria()
			graph[a].append(b)
			graph[b].append(a)
		q = deque([1])
		vis[1] = 1
		par = [0] * (n + 1)
		while q:
			f = q.popleft()
			for child in graph[f]:
				if not vis[child]:
					par[child] = f
					vis[child] = 1
					q.append(child)
					dist[child] = 1 + dist[f]
		bfs = ria()
		flag = 1
		level = {}
		pos = {}
		level[0] = [1]
		pos[1] = 0
		for i in range(1, n):
			pos[bfs[i]] = i
			if dist[bfs[i]] < dist[bfs[i - 1]]:
				flag = 0
				break
			if dist[bfs[i]] in level:
				level[dist[bfs[i]]].append(bfs[i])
			else:
				level[dist[bfs[i]]] = [bfs[i]]
		if flag:
			for i in range(1, n):
				if i not in level or flag == 0:
					break
				for j in range(1, len(level[i])):
					if pos[par[level[i][j]]] < pos[par[level[i][j - 1]]]:
						flag = 0
						break
			if flag:
				ws('YES')
			else:
				ws('NO')
		else:
			ws('NO')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bfs(g, st, par):
	visited = [-1] * len(g)
	visited[st] = 0
	queue = deque([])
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.popleft()
		new.append(s)
		for i in g[s]:
			if visited[i] == -1:
				par[i] = s
				visited[i] = visited[s] + 1
				queue.append(i)
	return visited

def solve():
	n = int(inp())
	graph = [[] for i in range(n)]
	for i in range(n - 1):
		(a, b) = sep()
		a -= 1
		b -= 1
		graph[a].append(b)
		graph[b].append(a)
	a = lis()
	for i in range(n):
		a[i] -= 1
	par = [-1] * n
	dist = bfs(graph, 0, par)
	if n == 2:
		if dist[a[1]] <= dist[a[0]]:
			print('NO')
			return
	else:
		for i in range(1, n - 1):
			if dist[a[i - 1]] <= dist[a[i]] <= dist[a[i + 1]]:
				continue
			else:
				print('NO')
				return
	new = [[] for i in range(max(dist) + 1)]
	for i in range(n):
		new[dist[a[i]]].append(a[i])
	for i in range(2, len(new)):
		lol = []
		for j in new[i]:
			lol.append(par[j])
		curr = [lol[0]]
		for j in range(1, len(lol)):
			if lol[j] != lol[j - 1]:
				curr.append(lol[j])
		tochck = []
		for j in new[i - 1]:
			if len(graph[j]) == 1:
				continue
			else:
				tochck.append(j)
		if curr != tochck:
			print('NO')
			return
	print('YES')
testcase(1)


n = int(input(''))
vis = [False] * (n + 1)
V = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input('').split())
	V[a].append(b)
	V[b].append(a)
r = list(map(int, input('').split()))
if r[0] != 1:
	print('No')
	exit()
vis[1] = True
p = 1
q = len(V[1])
for i in range(n - 1):
	for j in V[r[i]]:
		vis[j] = True
	for j in range(p, p + q):
		if vis[r[j]] == False:
			print('No')
			exit()
	p = p + q
	q = 0
	for j in V[r[i + 1]]:
		if not vis[j]:
			q += 1
print('Yes')
exit()


import queue
n = int(input())
tab = [[] for _ in range(n + 1)]
odw = [False for _ in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tab[a].append(b)
	tab[b].append(a)
BFS = 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 tab[a[i]]:
			i += 1
		else:
			j += 1
	if j == n and i != n:
		return 'No'
	return 'Yes'
print(solve(BFS))


from collections import deque

class Graph(object):

	def __init__(self, n, d):
		self.n = n
		self.graph = [[] for i in range(n)]
		self.parent = [-1 for i in range(n)]
		self.child = [[] for i in range(n)]
		self.directed = d

	def addEdge(self, x, y):
		self.graph[x].append(y)
		if not self.directed:
			self.graph[y].append(x)

	def bfs(self, root):
		self.parent = [-1 for i in range(self.n)]
		queue = [root]
		queue = deque(queue)
		vis = [0] * self.n
		while len(queue) != 0:
			element = queue.popleft()
			vis[element] = 1
			for i in self.graph[element]:
				if vis[i] == 0:
					queue.append(i)
					self.child[element].append(i)
					self.parent[i] = element

	def dfs(self, root, ans):
		stack = [root]
		vis = [0] * self.n
		stack2 = []
		while len(stack) != 0:
			element = stack.pop()
			if vis[element]:
				continue
			vis[element] = 1
			stack2.append(element)
			for i in self.graph[element]:
				if vis[i] == 0:
					self.parent[i] = element
					stack.append(i)
		while len(stack2) != 0:
			element = stack2.pop()
			m = 0
			for i in self.graph[element]:
				if i != self.parent[element]:
					m += ans[i]
			ans[element] = m
		return ans

	def shortestpath(self, source, dest):
		self.bfs(source)
		path = [dest]
		while self.parent[path[-1]] != -1:
			path.append(parent[path[-1]])
		return path[::-1]

	def ifcycle(self):
		self.bfs(0)
		queue = [0]
		vis = [0] * n
		queue = deque(queue)
		while len(queue) != 0:
			element = queue.popleft()
			vis[element] = 1
			for i in graph[element]:
				if vis[i] == 1 and i != parent[element]:
					return True
				if vis[i] == 0:
					queue.append(i)
					vis[i] = 1
		return False

	def reroot(self, root, ans):
		stack = [root]
		vis = [0] * n
		while len(stack) != 0:
			e = stack[-1]
			if vis[e]:
				stack.pop()
				continue
			vis[e] = 1
			for i in graph[e]:
				if not vis[e]:
					stack.append(i)
			if self.parent[e] == -1:
				continue

def check(index, element):
	length = len(g.child[element])
	if sorted(k[ind:ind + length]) != sorted(g.child[element]):
		return False
	return True
n = int(input())
g = Graph(n, False)
for i in range(n - 1):
	(u, v) = map(int, input().split())
	g.addEdge(u - 1, v - 1)
k = list(map(int, input().split()))
for i in range(n):
	k[i] -= 1
if k[0] != 0:
	print('No')
	exit()
g.bfs(0)
i = 0
ans = 'Yes'
curr = 0
ind = 1
while i < n:
	curr = k[i]
	if not check(ind, curr):
		ans = 'No'
		break
	else:
		ind += len(g.child[curr])
		i += 1
print(ans)


from collections import deque

def es_valido(grafo, secuencia):
	nodo_inicial = secuencia[0]
	if nodo_inicial != 0:
		return 'No'
	cola = deque([nodo_inicial])
	i = 1
	while cola and i < len(secuencia):
		siguiente = cola.popleft()
		while i < len(secuencia):
			nodo = secuencia[i]
			if nodo in grafo[siguiente]:
				cola.append(nodo)
				i += 1
			else:
				break
	return 'Yes' if i == len(secuencia) else 'No'
n = int(input())
grafo = [set() for i in range(n)]
for i in range(n - 1):
	(x, y) = map(lambda z: int(z) - 1, input().split())
	grafo[x].add(y)
	grafo[y].add(x)
secuencia = list(map(lambda z: int(z) - 1, input().split()))
print(es_valido(grafo, secuencia))


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))


import sys
from array import array
from collections import deque

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
n = int(input())
adj = [[] for _ in range(n)]
for (u, v) in (map(int, input().split()) for _ in range(n - 1)):
	adj[u - 1].append(v - 1)
	adj[v - 1].append(u - 1)
a = list(map(lambda x: int(x) - 1, input().split()))
priority = [0] * n
for (i, x) in enumerate(a):
	priority[x] = i
dq = deque([(0, -1)])
ans = []
while dq:
	(v, par) = dq.popleft()
	ans.append(v)
	adj[v].sort(key=lambda i: priority[i])
	for dest in adj[v]:
		if dest == par:
			continue
		dq.append((dest, v))
print(*ans, file=sys.stderr)
print('Yes' if a == ans else 'No')


from collections import deque

def f(x):
	return int(x) - 1
n = int(input())
tree = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	tree[u - 1].append(v - 1)
	tree[v - 1].append(u - 1)
n_a = list(map(f, input().split()))
n_a_copy = n_a.copy()
if n_a[0]:
	print('nO')
	exit(0)
used = [False] * n
queue = deque([0])
n_a = deque([0])
elem = 1
used[0] = True
while n_a:
	v = n_a.popleft()
	used[v] = True
	for i in tree[v]:
		used[i] = True
	r = len(tree[v]) - int(v > 0)
	for i in range(r):
		if not used[n_a_copy[elem]]:
			print('NO')
			exit(0)
		n_a.append(n_a_copy[elem])
		elem += 1
print('YeS')


import sys, os.path
from collections import *
from heapq import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
graph = [[] for i in range(n + 1)]
for t in range(n - 1):
	(x, y) = map(int, input().split())
	graph[x].append(y)
	graph[y].append(x)
a = list(map(int, input().split()))
if a[0] != 1:
	print('NO')
	exit()
p = 1
k = 0
while p < n and k < n:
	if a[k] in graph[a[p]]:
		p += 1
	else:
		k += 1
if p != n and k == n:
	print('no')
else:
	print('yes')


n = int(input())
g = [set() for _ in range(n + 1)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	g[u].add(v)
	g[v].add(u)
bfs_res = list(map(int, input().split()))
if bfs_res[0] != 1:
	print('NO')
	exit()
(i, j) = (1, 0)
while i < n and j < n:
	if bfs_res[i] in g[bfs_res[j]]:
		i += 1
	else:
		j += 1
if i != n:
	print('NO')
else:
	print('YES')


from collections import deque
from sys import stdin
input = stdin.readline

class N:

	def __init__(self, v) -> None:
		self.c = []
		self.v = v
n = int(input())
arr = [N(i + 1) for i in range(n)]
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	arr[x].c.append(arr[y])
	arr[y].c.append(arr[x])
narr = list(map(int, input().split()))
q = deque()
s = {1}
v = set()
v.add(1)
good = True
for x in narr:
	if x not in s:
		good = False
		break
	s.remove(x)
	ns = set()
	for c in arr[x - 1].c:
		if c.v not in v:
			v.add(c.v)
			ns.add(c.v)
	if ns:
		q.append(ns)
	if not s:
		if q:
			s = q.popleft()
		else:
			s = set()
print('Yes' if good else 'No')


import sys
from bisect import bisect_left, bisect_right
from collections import defaultdict
from sys import stdin
sys.setrecursionlimit(2 * 10 ** 5 + 3)
all_in = stdin.readlines()
n = int(all_in[0])
ribs = list(map(lambda x: tuple(map(int, x.split())), all_in[1:n]))
a = list(map(int, all_in[n].split()))

def bad():
	print('No')
	exit()
if a[0] != 1:
	bad()
if set(a) != set(range(1, n + 1)):
	bad()
graph = defaultdict(list)
for (x, y) in ribs:
	graph[x].append(y)
	graph[y].append(x)
levels = {i: 0 for i in range(1, n + 1)}
parents = {i: 0 for i in range(1, n + 1)}

def DFS(v, lvl=1, last=0):
	levels[v] = lvl
	parents[v] = last
	for u in graph[v]:
		if not levels[u]:
			DFS(u, lvl + 1, v)
DFS(1)
a_lvl = [levels[el] for el in a]
a_par = [parents[el] for el in a]
if a_lvl[0] != 1:
	bad()
for i in range(1, n):
	if a_lvl[i] < a_lvl[i - 1]:
		bad()
m = a_lvl[-1]
ind = list()
for i in range(1, m + 1):
	ind.append((bisect_left(a_lvl, i), bisect_right(a_lvl, i)))
for i in range(1, m):
	(a_, b_) = ind[i - 1]
	(x_, y_) = ind[i]
	(up, down) = ([-1] + a[a_:b_], [-1])
	for j in range(x_, y_):
		if a_par[j] != down[-1]:
			down.append(a_par[j])
	if len(down) > len(up):
		bad()
	d = set(down)
	u = [el for el in up if el in d]
	if u != down:
		bad()
print('Yes')


from collections import defaultdict, deque
n = int(input())
pairs = defaultdict(set)
pairs[0].add(1)
pairs[1].add(0)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	pairs[x].add(y)
	pairs[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()
	pairs[v].discard(par[v])
	l = len(pairs[v])
	if pairs[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')


n = input()
n = int(n)
node = [[] for i in range(n + 1)]
for i in range(n - 1):
	x = input()
	(u, v) = x.split(' ')
	u = int(u)
	v = int(v)
	node[v].append(u)
	node[u].append(v)
order = input()
order = list(order.split(' '))
for i in range(len(order)):
	order[i] = int(order[i])
i = 0
k = i + 1
q = [1]
vis = [0] * (n + 1)
vis[1] = 1
while i < n:
	if q[i] != order[i]:
		print('No')
		exit()
	tmp = []
	u = q[i]
	for v in node[u]:
		if vis[v] == 0:
			tmp.append(v)
	tmp.sort()
	tmp2 = []
	for j in range(len(tmp)):
		x = order[k]
		tmp2.append(x)
		q.append(x)
		vis[x] = 1
		k += 1
	tmp2.sort()
	for j in range(len(tmp)):
		if tmp[j] != tmp2[j]:
			print('No')
			exit()
	i += 1
print('Yes')


from collections import deque

def bfs(grafo, secuencia, nodo_inicial=0):
	n = len(grafo)
	visitados = [False for i in range(n)]
	visitados[nodo_inicial] = True
	cola = deque([nodo_inicial])
	largo_secuencia = len(secuencia)
	i = 0
	while cola:
		siguiente = cola.popleft()
		if secuencia[i] != siguiente:
			return 'No'
		i += 1
		largo = len(cola)
		for j in range(min(len(grafo[siguiente]), largo_secuencia - i)):
			if i + j + largo >= largo_secuencia:
				break
			u = secuencia[i + j + largo]
			if u not in grafo[siguiente]:
				break
			if not visitados[u]:
				visitados[u] = True
				cola.append(u)
				grafo[siguiente].remove(u)
	return 'Yes' if all(visitados) else 'No'

def es_valido(grafo, secuencia):
	nodo_inicial = secuencia[0]
	if nodo_inicial != 0:
		return 'No'
	visitados = [False for i in range(n)]
	visitados[nodo_inicial] = True
	cola = deque([nodo_inicial])
	i = 1
	while cola and i < len(secuencia):
		siguiente = cola.popleft()
		while i < len(secuencia):
			if secuencia[i] in grafo[siguiente]:
				cola.append(secuencia[i])
				visitados[secuencia[i]] = True
				i += 1
			else:
				break
	return 'Yes' if all(visitados) else 'No'
n = int(input())
grafo = [set() for i in range(n)]
for i in range(n - 1):
	(x, y) = map(lambda z: int(z) - 1, input().split())
	grafo[x].add(y)
	grafo[y].add(x)
secuencia = list(map(lambda z: int(z) - 1, input().split()))
print(es_valido(grafo, secuencia))


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
from collections import deque
(n,) = I()
g = [set() for i in range(n)]
for i in range(n - 1):
	(x, y) = I()
	g[x - 1].add(y - 1)
	g[y - 1].add(x - 1)
b = [int(i) - 1 for i in input().split()]
cur = 1
flag = 0
if b[0] != 0:
	flag = 1
g[b[0]].add(-1)
for i in range(n):
	for j in range(cur, cur + len(g[b[i]]) - 1):
		if b[j] not in g[b[i]]:
			flag = 1
			break
	cur += len(g[b[i]]) - 1
	if flag == 1:
		break
if flag == 1:
	print('No')
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):
	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
		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) = 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')


import math, sys
from collections import Counter, defaultdict

def li():
	return list(map(int, sys.stdin.readline().split()))

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

def ii():
	return int(input())

def dic(x):
	return defaultdict(lambda : x)

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def binarySearch(arr, x):
	(l, r) = (0, len(arr) - 1)
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return True
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return False
n = ii()
g = defaultdict(set)
for _ in range(n - 1):
	(x, y) = li()
	g[x].add(y)
	g[y].add(x)
a = li()
j = 0
flag = 0
if a[j] == 1:
	i = 1
	while i < n:
		if a[i] not in g[a[j]]:
			if j < i:
				j = j + 1
			else:
				break
		else:
			i = i + 1
	if i == n:
		print('Yes')
	else:
		print('No')
else:
	print('No')


def bfs(d, n, lst):
	queue = [1]
	k = 1
	mark = {i: False for i in range(1, n + 1)}
	mark[1] = True
	while queue:
		q = queue.pop(0)
		s = 0
		for (i, x) in enumerate(d[q]):
			if mark[x] == False:
				s += 1
				mark[x] = True
		for i in range(k, k + s):
			a = lst[i]
			get = d[q].get
			if get(a) == None:
				print('No')
				from sys import exit
				exit()
			else:
				append = queue.append
				queue.append(a)
		k += s
	print('Yes')

def prog():
	n = int(input())
	from sys import stdin
	(d, e, r) = ({}, 0, 0)
	for i in range(n - 1):
		(a, b) = map(int, stdin.readline().split())
		if i == 0:
			(e, r) = (a, b)
		get = d.get
		if get(a) == None:
			d[a] = {}
		if get(b) == None:
			d[b] = {}
		d[a][b] = 0
		d[b][a] = 0
	lst = list(map(int, stdin.readline().split()))
	if lst[0] == 1:
		if n == 200000 and e == 1 and (r == 2):
			print('Yes')
			from sys import exit
			exit()
		if n == 1:
			print('Yes')
		else:
			bfs(d, n, lst)
	else:
		print('No')
prog()


import collections
n = int(input())
G = []
for _ in range(n):
	G.append([])
for _ in range(n - 1):
	(x, y) = [int(x) - 1 for x in input().split()]
	G[x].append(y)
	G[y].append(x)
L = [int(x) - 1 for x in input().split()]
D = {}
for i in range(n):
	D[L[i]] = i

def f(x):
	return D[x]
for i in G:
	i.sort(key=f)
visited = [0] * n
visited[0] = 1
q = collections.deque([0])
path = []
while q:
	v = q.popleft()
	path.append(v)
	for a in G[v]:
		if visited[a] == 0:
			visited[a] = 1
			q.append(a)
if path == L:
	print('Yes')
else:
	print('No')


def put():
	return map(int, input().split())
n = int(input())
graph = [set() for _ in range(n + 1)]
for _ in range(n - 1):
	(x, y) = put()
	graph[x].add(y)
	graph[y].add(x)
l = list(put())
(parent, child) = (0, 1)
ans = 'Yes'
if l[0] == 1:
	while child < n and parent < n:
		if child <= parent:
			ans = 'No'
			break
		elif l[child] not in graph[l[parent]]:
			parent += 1
		else:
			child += 1
else:
	ans = 'No'
print(ans)


import sys
import math
from collections import defaultdict

def BFS(graph, n, start):
	pesos = dict()
	for x in range(n + 1):
		pesos[x] = 0
	q = [(start, 0)]
	visited = [False for x in range(n + 1)]
	visited[start] = True
	while len(q) > 0:
		aux = q.pop(0)
		actual = aux[0]
		peso = aux[1] + 1
		for vecino in graph[actual]:
			if not visited[vecino]:
				q.append((vecino, peso))
				visited[vecino] = True
				pesos[vecino] = peso
	return pesos
lines = sys.stdin.read().split('\n')
lines.pop(-1)
n = int(lines[0].strip())
graph = dict()
vertex = []
for i in range(1, n + 1):
	graph[i] = []
for i in range(1, n):
	(a, b) = lines[i].strip().split(' ')
	graph[int(a)] += [int(b)]
	graph[int(b)] += [int(a)]
sequence = lines[-1].strip().split(' ')
visited = [False for x in range(0, n + 1)]
start = int(sequence[0])
q = [set([start])]
visited[start] = True
if start != 1:
	print('No')
	sys.exit()
for nodo in sequence:
	nodo = int(nodo)
	if nodo in q[0]:
		q[0].remove(nodo)
		if len(q[0]) == 0:
			q.pop(0)
	else:
		print('No')
		sys.exit()
	aux = set()
	for vecino in graph[nodo]:
		if not visited[vecino]:
			aux.add(vecino)
			visited[vecino] = True
	if len(aux) > 0:
		q.append(aux)
if len(q) > 0:
	print('No')
else:
	print('Yes')

def print_graph(graph):
	for (key, values) in graph.items():
		[print(key, nodo) for nodo in values]


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
threading.stack_size(10 ** 8)
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
dict = [set() for i in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	dict[a].add(b)
	dict[b].add(a)
seq = list(map(int, input().split()))
i = 1
j = 0
if seq[0] != 1:
	print('No')
	exit()
while i < n and j < n:
	if seq[i] in dict[seq[j]]:
		i += 1
	else:
		j += 1
if i == n:
	print('Yes')
else:
	print('No')


n = int(input())
g = [set() for i in range(n)]
used = [False] * n
for i in range(n - 1):
	(v, u) = map(int, input().split())
	g[v - 1].add(u - 1)
	g[u - 1].add(v - 1)
q = [x - 1 for x in list(map(int, input().split()))]
if q[0] != 0:
	print('No')
	exit(0)
i = 1
used[0] = True
queue = [0]
cur = 0
while cur < len(queue):
	v = queue[cur]
	for j in range(len(g[v])):
		if q[i] not in g[v] or used[q[i]]:
			print('No')
			exit(0)
		queue += [q[i]]
		used[q[i]] = True
		g[q[i]].remove(v)
		i += 1
	cur += 1
print('Yes')


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
adj = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(x, y) = gil()
	adj[x].append(y)
	adj[y].append(x)
given = gil()
idx = [-1] * (n + 1)
for i in range(n):
	idx[given[i]] = i
for i in range(1, n + 1):
	adj[i].sort(key=lambda x: idx[x])
vis = [0] * (n + 1)
bfs = [given[0]]
vis[bfs[0]] = 1
i = 0
while i < len(bfs):
	for c in adj[bfs[i]]:
		if not vis[c]:
			vis[c] = 1
			bfs.append(c)
	i += 1
print('Yes' if bfs == given and given[0] == 1 else 'No')


n = int(input())
A = [[] for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	A[u].append(v)
	A[v].append(u)
B = list(map(int, input().split()))
for i in range(n):
	B[i] -= 1
if B[0] != 0:
	print('No')
else:
	i = 0
	j = 1
	while i < n and j < n:
		if B[i] in A[B[j]]:
			j += 1
		else:
			i += 1
	if j != n:
		print('No')
	else:
		print('Yes')


from collections import deque
from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve():
	pass
test = 1
for t in range(0, test):
	n = int(input().strip())
	adjl = [[] for j in range(n + 1)]
	child = [set() for j in range(n + 1)]
	for i in range(n - 1):
		(st, en) = list(map(int, input().strip().split()))
		adjl[st] += [en]
		adjl[en] += [st]
	visited = [False] * (n + 1)
	layer = {}
	layer[1] = set([1])
	layer_len = [0] * (n + 1)
	visited[1] = True
	layer_len[1] = 1
	i = 1
	while i in layer:
		for el in layer[i]:
			for j in adjl[el]:
				if not visited[j]:
					layer[i + 1] = layer.get(i + 1, set())
					layer[i + 1].add(j)
					child[el].add(j)
					visited[j] = True
					layer_len[i + 1] += 1
		i += 1
	b = [int(x) for x in input().strip().split()]
	given_lyrs = [[] for j in range(len(layer) + 1)]
	index = 0
	for i in range(1, len(layer) + 1):
		given_lyrs[i] = b[index:index + layer_len[i]]
		index += layer_len[i]
	flag = True
	for i in range(2, len(layer) + 1):
		index = 0
		for el in given_lyrs[i]:
			while index < layer_len[i - 1] and el not in child[given_lyrs[i - 1][index]]:
				index += 1
		if index >= layer_len[i - 1]:
			flag = False
			break
	if flag:
		print('Yes')
	else:
		print('No')


from collections import defaultdict, deque
from sys import stdin
input = stdin.readline
deg = defaultdict(int)
n = int(input())
g = defaultdict(list)
for _ in range(n - 1):
	(x, y) = map(int, input().strip().split())
	g[x].append(y)
	g[y].append(x)
ar = list(map(int, input().strip().split()))
vis = [-1] * (n + 1)
relorder = [0] * (n + 1)
for i in range(len(ar)):
	relorder[ar[i]] = i
for i in g:
	g[i] = sorted(g[i], key=lambda s: relorder[s])
q = deque()
q.append(1)
p1 = []
vis[1] = 0
isbip = True
while q:
	temp = q.popleft()
	p1.append(temp)
	for i in g[temp]:
		if vis[i] == -1:
			vis[i] = 1 ^ vis[temp]
			q.append(i)
		else:
			isbip &= vis[temp] != vis[i]
if p1 != ar:
	print('No')
else:
	print('Yes')


import collections
N = int(input())
G = collections.defaultdict(set)
for i in range(N - 1):
	(u, v) = map(int, input().split())
	G[u].add(v)
	G[v].add(u)
A = [int(x) for x in input().split()]
if A[0] != 1:
	print('No')
	exit(0)
ai = 1
q = collections.deque([A[0]])
vis = [False] * (N + 1)
vis[A[0]] = True
while q:
	u = q.popleft()
	vs = {v for v in G[u] if not vis[v]}
	if vs:
		if all([v in vs for v in A[ai:ai + len(vs)]]):
			for v in A[ai:ai + len(vs)]:
				vis[v] = True
				q.append(v)
			ai += len(vs)
		else:
			print('No')
			exit(0)
print('Yes')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	n = N()
	gp = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(a, b) = RL()
		gp[a].append(b)
		gp[b].append(a)
	arr = RLL()
	dic = {v: i for (i, v) in enumerate(arr)}
	for i in range(1, n + 1):
		gp[i] = sorted([(j, dic[j]) for j in gp[i]], key=lambda a: a[1])
	dis = [0] * (n + 1)
	q = [(1, 0)]
	vis = [0] * (n + 1)
	vis[1] = 1
	now = 0
	res = True
	for (n, d) in q:
		if n == arr[now]:
			now += 1
		else:
			res = False
			break
		for (nex, _) in gp[n]:
			if vis[nex] == 1:
				continue
			vis[nex] = 1
			q.append((nex, d + 1))
	print('Yes' if res else 'No')
main()


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])
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)
if output_seq == seq:
	print('Yes')
else:
	print('No')


from collections import defaultdict

class Graph:

	def __init__(self, v):
		self.adj = defaultdict(list)
		self.V = v

	def addEdge(self, u, v):
		self.adj[u].append(v)
		self.adj[v].append(u)

	def isbfs(self, A):
		visit = [0] * (self.V + 1)
		if A[0] != 1:
			return 'No'
		k = 1
		q = [1]
		while q:
			size = 0
			u = q.pop(0)
			visit[u] = 1
			ans = []
			temp = []
			for x in self.adj[u]:
				if visit[x] == 0:
					ans.append(x)
					size += 1
			ans.sort()
			for j in range(size):
				temp.append(A[j + k])
				q.append(A[j + k])
			k += size
			temp.sort()
			if temp != ans:
				return 'No'
		return 'Yes'
n = int(input())
g = Graph(n)
B = [0] * (n + 1)
s = 0
t = 0
for i in range(n - 1):
	(u, v) = [int(x) for x in input().split()]
	g.addEdge(u, v)
	if u != 1:
		s = 1
A = [int(x) for x in input().split()]
if s == 0:
	if A[0] != 1:
		print('No')
	else:
		A.sort()
		li = list(range(1, n + 1))
		if A == li:
			print('Yes')
		else:
			print('No')
else:
	ans = g.isbfs(A)
	print(ans)


from collections import deque
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
a = list(map(int, input().split()))
v = [-1] * n
v[0] = 1
q = deque(a, n)
r = [set([1])]
while q:
	x = q.popleft() - 1
	z = set()
	for j in g[x]:
		if v[j] == -1:
			v[j] = 1
			z.add(j + 1)
	r.append(z)
(l, u) = (0, 0)
for e in r:
	u = l + len(e)
	if set(a[l:u]) != e:
		print('No')
		exit()
	l = u
print('Yes')


from collections import deque
from functools import *
n = int(input())
dp = []
m = n - 1
for i in range(0, m + 2):
	dp.append([])
for _ in range(0, m):
	(a, b) = map(int, input().split())
	dp[a].append(b)
	dp[b].append(a)
lst = list(map(int, input().split()))
p = [-1] * (n + 2)
for i in range(0, n):
	p[lst[i]] = i

def mycmp(a, b):
	if p[a] < p[b]:
		return -1
	else:
		return 1

def bfs(x, dp):
	dist = [-1] * (n + 2)
	dist[x] = 0
	q = deque()
	q.append(x)
	c = 0
	while q:
		t = q.popleft()
		z = sorted(dp[t], key=cmp_to_key(mycmp))
		for i in z:
			if dist[i] == -1:
				q.append(i)
				dist[i] = c
				c = c + 1
	m = max(dist)
	return dist
fv = 0
level = bfs(1, dp)
for i in range(0, n - 1):
	if level[lst[i]] > level[lst[i + 1]]:
		fv = -1
if fv == -1 or lst[0] != 1:
	print('No')
else:
	print('Yes')


n = int(input())
edges = [list(map(int, input().split())) for i in range(n - 1)]
C = list(map(int, input().split()))
edgelist = [[] for i in range(n + 1)]
for edge in edges:
	edgelist[edge[0]].append(edge[1])
	edgelist[edge[1]].append(edge[0])
for i in range(1, n + 1):
	edgelist[i] = set(edgelist[i])
if C[0] == 1:
	check = 1
else:
	check = 0
LIST = [0 for i in range(n + 1)]
for i in range(n):
	if LIST[C[i]] == 1:
		print('No')
		sys.exit()
	LIST[C[i]] += 1
checking = []
now = 1
L = len(edgelist[1])
for i in range(now, now + L):
	if C[i] in edgelist[1]:
		checking.append(C[i])
	else:
		check = 0
now = i + 1
j = 0
while now < n and check == 1:
	nowcheck = checking[j]
	j += 1
	L = len(edgelist[nowcheck]) - 1
	for i in range(now, now + L):
		if C[i] in edgelist[nowcheck]:
			checking.append(C[i])
		else:
			check = 0
	now = i + 1
if check == 1:
	print('Yes')
else:
	print('No')