# Valid BFS?

The BFS algorithm is defined as follows.

1. 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.
2. Extract a vertex $v$ from the head of the queue $q$.
3. Print the index of vertex $v$.
4. 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$.
5. If the queue is not empty, continue from step 2.
6. 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

41 21 32 41 2 3 4

output

Yes

input

41 21 32 41 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.

Solution:

#include <bits/stdc++.h>

using namespace std;

void err() {
cout << "No" << '\n';
exit(0);
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
vector<int> order(n);
for (int i = 0; i < n; i++) {
cin >> order[i];
order[i]--;
}
if (order[0] != 0) {
err();
}
vector<int> was(n, 0);
was[0] = 1;
int b = 0;
int e = 1;
while (b < e) {
int i = order[b];
set<int> put;
for (int j : g[i]) {
if (!was[j]) {
put.insert(j);
}
}
set<int> get;
for (int id = e; id < e + (int) put.size(); id++) {
get.insert(order[id]);
}
if (put != get) {
err();
}
for (int x : put) {
was[x] = 1;
}
e += (int) put.size();
b++;
}
if (e != n) {
err();
}
cout << "Yes" << '\n';
return 0;
}