#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int pai[MAX];
bool cor[MAX];

void dfs(int v, int p)
{
	pai[v] = p;
	for(int &u : G[v])
		if(u != p)
			dfs(u, v);
}

bool bfs(int v)
{
	queue<int> q;
	q.push(v);
	cor[v] = true;
	int idx = 1;
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		int sz = G[u].size();
		REP(i, sz)
		{
			int w = or_bfs[idx];
			idx++;
			if(cor[w]) continue;
			if(pai[w] != u)
				return false;
			q.push(w);
			cor[w] = true;
		}
	}
	return true;
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	REP(i, n) scanf(" %d", &or_bfs[i]), or_bfs[i]--;

	dfs(0, -1);
	bool fl = bfs(0);

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX], P[MAX];
int nivel[MAX], ans[MAX], mark[MAX];

void dfs(int v, int p, int d)
{
	nivel[v] = d;
	for(int &u : G[v])
		if(u != p)
			dfs(u, v, d + 1);
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}

	REP(i, n)
	{
		scanf(" %d", &or_bfs[i]);
		or_bfs[i]--;
		if(mark[or_bfs[i]])
			return puts("No"), 0;
		mark[or_bfs[i]]++;
	}

	dfs(0, -1, 1);

	REP(i, n) ans[i] = nivel[or_bfs[i]], P[i] = i;

	sort(P, P + n, [](int a, int b){ return ans[a] < ans[b]; });

	bool fl = true;
	REP(i, n)
		if(P[i] != i)
			fl = false, i = n;

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int pai[MAX];
bool cor[MAX];

void dfs(int v, int p)
{
	pai[v] = p;
	for(int &u : G[v])
		if(u != p)
			dfs(u, v);
}

bool bfs(int v)
{
	queue<int> q;
	q.push(v);
	cor[v] = true;
	int idx = 1;
	while(!q.empty() and idx < n)
	{
		int u = q.front();
		q.pop();
		int sz = G[u].size();
		REP(i, sz)
		{
			int w = or_bfs[idx];
			if(cor[w]) continue;
			if(pai[w] != u)
				return false;
			q.push(w);
			cor[w] = true;
			idx++;
		}
	}
	return true;
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	REP(i, n) scanf(" %d", &or_bfs[i]), or_bfs[i]--;

	dfs(0, -1);
	bool fl = bfs(0);

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int nivel[MAX];

void dfs(int v, int p, int d)
{
	nivel[v] = d;
	for(int &u : G[v])
		if(u != p)
			dfs(u, v, d + 1);
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}

	REP(i, n)
	{
		scanf(" %d", &or_bfs[i]);
		or_bfs[i]--;
	}

	memset(nivel, 63, sizeof(nivel));

	dfs(0, -1, 1);

	bool fl = true;

	for(int i = 0; i < n - 1; i++)
	{
		if(nivel[or_bfs[i]] == nivel[or_bfs[i + 1]] or nivel[or_bfs[i]] == nivel[or_bfs[i + 1]] - 1) continue;
		fl = false;
		i = n;
	}
	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int nivel[MAX], ans[MAX];

void bfs(int v)
{
	queue<int> q;
	memset(nivel, -1, sizeof(nivel));
	q.push(v);
	nivel[v] = 0;
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for(int &w : G[u])
			if(nivel[w] == -1)
			{
				nivel[w] = nivel[u] + 1;
				q.push(w);
			}
	}
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	REP(i, n) scanf(" %d", &or_bfs[i]), or_bfs[i]--;

	bfs(or_bfs[0]);

	REP(i, n) ans[i] = nivel[or_bfs[i]];

	bool fl = is_sorted(ans, ans + n);

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int pai[MAX];
bool cor[MAX];

void dfs(int v, int p)
{
	pai[v] = p;
	for(int &u : G[v])
		if(u != p)
			dfs(u, v);
}

bool bfs(int v)
{
	queue<int> q;
	q.push(v);
	cor[v] = true;
	G[v].pb(v);
	int idx = 1;
	while(!q.empty())
	{
		if(idx >= n) return true;
		int u = q.front();
		q.pop();
		int sz = G[u].size();
		REP(i, sz - 1)
		{
			if(idx >= n) return true;
			int w = or_bfs[idx];
			idx++;
			if(cor[w]) continue;
			if(pai[w] != u)
				return false;
			q.push(w);
			cor[w] = true;
		}
	}
	return true;
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	REP(i, n) scanf(" %d", &or_bfs[i]), or_bfs[i]--;

	if(or_bfs[0]) return puts("No"), 0;

	dfs(0, -1);
	bool fl = bfs(0);

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int nivel[MAX], ans[MAX], mark[MAX];

void bfs(int v)
{
	queue<int> q;
	memset(nivel, -1, sizeof(nivel));
	q.push(v);
	nivel[v] = 0;
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for(int &w : G[u])
			if(nivel[w] == -1)
			{
				nivel[w] = nivel[u] + 1;
				q.push(w);
			}
	}
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}

	REP(i, n)
	{
		scanf(" %d", &or_bfs[i]);
		or_bfs[i]--;
		if(mark[or_bfs[i]])
			return puts("No"), 0;
		mark[or_bfs[i]]++;
	}

	if(or_bfs[0] != 0) return puts("No"), 0;

	bfs(0);

	REP(i, n) ans[i] = nivel[or_bfs[i]];

	bool fl = is_sorted(ans, ans + n);

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int nivel[MAX], ans[MAX];

void bfs(int v)
{
	queue<int> q;
	memset(nivel, -1, sizeof(nivel));
	q.push(v);
	nivel[v] = 0;
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for(int &w : G[u])
			if(nivel[w] == -1)
			{
				nivel[w] = nivel[u] + 1;
				q.push(w);
			}
	}
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	REP(i, n) scanf(" %d", &or_bfs[i]), or_bfs[i]--;

	bfs(0);

	REP(i, n) ans[i] = nivel[or_bfs[i]];

	bool fl = is_sorted(ans, ans + n);

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
///不要忘记加10
const int MAXN=2e5+10;
int N;
vector<int> G[MAXN];
queue<int>q;
set<int>visited;
int vis[MAXN];
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
        G[e].push_back(s);
    }
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    vis[t]=true;
    if(t!=1)f=false;
    else
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            if(!vis[G[t][i]])visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            if(!vis[k])
            {
                q.push(k);
                vis[k]=true;
            }
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
///不要忘记加10
const int MAXN=2e5+10;
int N;
vector<int> G[MAXN];
queue<int>q;
set<int>visited;
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
    }
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    if(t!=1)f=false;
    else
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            q.push(k);
            vis[k]=true;
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int MAXN=2e5;
int N;
vector<int> G[MAXN];
queue<int>q;
set<int>visited;
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
    }
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            q.push(k);
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int MAXN=2e5+10;
int N;
vector<int>G[MAXN];
vector<int>v;
vector<int>vr;
int visited[MAXN];
void bfs(int s)
{
    visited[s]=true;
    queue<int>q;
    q.push(s);
    v.push_back(s);
    vr.push_back(s);
    while(!q.empty()){
        int f=q.front();
        q.pop();
        int curP=v.size();
        for(int i=0;i<G[f].size() ;i++ ){
            int nxt =G[f][i];
            if(!visited[nxt]){
                q.push(nxt);
                v.push_back(nxt);
                vr.push_back(nxt);
                visited[nxt]=true;
            }
        }
        reverse(vr.begin()+curP,vr.end());
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    int t=N-1;
    while(t--){
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    bfs(1);
    bool f=true;
    vector<int>vi;
    for(int i=1;i<=N ;i++ ){
        int t;
        scanf("%d",&t);
        vi.push_back(t);
    }
    string ans=(vi==v||vi==vr)?"Yes":"No";
    printf("%s\n",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
///不要忘记加10
const int MAXN=2e5+10;
int N;
vector<int> G[MAXN];
queue<int>q;
set<int>visited;
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
    }
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    if(t!=1)f=false;
    else
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            q.push(k);
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int MAXN=2e5+10;
int N;
vector<int> G[MAXN];
queue<int>q;
set<int>visited;
int vis[MAXN];
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
        G[e].push_back(s);
    }
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    vis[t]=true;
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            if(!vis[G[t][i]])visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            if(!vis[k])
            {
                q.push(k);
                vis[k]=true;
            }
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int MAXN=2e5;
int N;
vector<int> G[MAXN];
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
    }
    queue<int>q;
    set<int>visited;
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            q.push(k);
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
///不要忘记加100
const int MAXN=2e5+10;
int N;
vector<int> G[MAXN];
queue<int>q;
set<int>visited;
int vis[MAXN];
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
        G[e].push_back(s);
    }
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    vis[t]=true;
    if(t!=1)f=false;
    else
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            if(!vis[G[t][i]])visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            if(!vis[k])
            {
                q.push(k);
                vis[k]=true;
            }
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int MAXN=2e5;
int N;
vector<int> G[MAXN];
queue<int>q;
set<int>visited;
int vis[MAXN];
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<N;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        G[s].push_back(e);
        G[e].push_back(s);
    }
    bool f=true;
    int t;
    scanf("%d",&t);
    q.push(t);
    vis[t]=true;
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=0;i<G[t].size();i++){
            if(!vis[G[t][i]])visited.insert(G[t][i]);
        }
        while(!visited.empty()){
            int k;
            scanf("%d",&k);
            if(visited.count(k)){
                visited.erase(k);
            }
            else {
                f=false;break;
            }
            if(!vis[k])
            {
                q.push(k);
                vis[k]=true;
            }
        }
        if(!f)break;
    }
    string ans=f?"Yes":"No";
    printf("%s",ans.c_str());
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int MAXN=2e5+10;
int N;
vector<int>G[MAXN];
int depth[MAXN];
int visited[MAXN];
void bfs(int s)
{
    visited[s]=true;
    depth[s]=0;
    queue<int>q;
    q.push(s);
    while(!q.empty()){
        int f=q.front();
        q.pop();
        for(int i=0;i<G[f].size() ;i++ ){
            int nxt =G[f][i];
            if(!visited[nxt]){
                depth[nxt]=depth[f]+1;
                q.push(nxt);
                visited[nxt]=true;
            }
        }
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&N);
    int t=N-1;
    while(t--){
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    bfs(1);
    bool f=true;
    int cur,nxt;
    scanf("%d",&cur);
    for(int i=1;i<=N-1 ;i++ ){
        scanf("%d",&nxt);
        if(depth[cur]>depth[nxt]){
            f=false;
        }
        cur=nxt;
    }
    string ans=f?"Yes":"No";
    printf("%s\n",ans.c_str());
}


#include<iostream>
#include<set>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 200010;
int n,vis[maxn];
queue<int> order,Q;
set<int> V;
vector<int> G[maxn];
int main() {
	ios::sync_with_stdio(false);
	cin>>n;
	for(register int i = 1;i<n;++i) {
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(register int i = 1;i<=n;++i) {
		int t;
		cin>>t;
		order.push(t);
	}
	Q.push(1);vis[1]=1;
	if(order.front()!=1) {
		cout<<"No"<<endl;
		return 0;
	}
	order.pop();
	while(!Q.empty()) {
		int u = Q.front();Q.pop();
		vis[u]=1;
		for(auto x : G[u]) {
			if(vis[x]) continue;
			V.insert(x);
		}
		while(!V.empty()) {
			if(V.count(order.front())) {
				V.erase(order.front());
				Q.push(order.front());
				order.pop();
			} else {
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
const int maxn = 200010;
int n,nxt[maxn],to[maxn],hd[maxn],fa[maxn],tot=0,d[maxn],num[maxn],cnt[maxn],chd[maxn];
int queue[maxn],head,tail;
inline void add(int a,int b) {
	nxt[++tot]=hd[a];
	hd[a]=tot;
	to[tot]=b;
	return;
}
inline void dfs(int u) {
	for(register int i = hd[u];i;i=nxt[i]) {
		int nx = to[i];
		if(d[nx]) continue;
		chd[u]++;
		fa[nx]=u;
		d[nx]=d[u]+1;
		dfs(nx);
	}
	return;
}
int main() {
	scanf("%d",&n);
	for(register int i = 1;i<n;++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	d[1]=fa[1]=1;
	dfs(1);
#ifdef DEBUG
	for(register int i  = 1;i<=n;++i) printf("%d ",d[i]);
	puts("");
#endif
	for(register int i = 1;i<=n;++i) num[d[i]]+=1;
	int cur = 1;
	head=tail=1;
	queue[tail]=1;cnt[1]=1;
	int ign;
	scanf("%d",&ign);
	for(register int i = 2;i<=n;++i) {
		int u;
		scanf("%d",&u);
		cnt[d[u]]++;
		if(d[u]>d[queue[head]]) {
			if(d[u]!=d[queue[head]]+1) {
				puts("No");
				return 0;
			}
			if(fa[u]=queue[head]) {
				chd[queue[head]]--;
				if(chd[queue[head]]==0) head++;
			}
			else {
#ifdef DEBUG
				printf("%d\n",i);
#endif
				puts("No");
				return 0;
			}
		}
		queue[++tail]=u;
	}
	for(register int i = 1;i<=n;++i)
		if(num[i]!=cnt[i]) {
#ifdef DEBUG
			puts("Err 2");
			printf("%d\n%d %d\n",i,num[i],cnt[i]);
#endif
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}


#include<cstdio>
#include<algorithm>
const int maxn = 200010;
int n,nxt[maxn],to[maxn],hd[maxn],fa[maxn],tot=0,d[maxn],num[maxn],cnt[maxn],chd[maxn];
int queue[maxn],head,tail;
inline void add(int a,int b) {
	nxt[++tot]=hd[a];
	hd[a]=tot;
	to[tot]=b;
	return;
}
inline void dfs(int u) {
	for(register int i = hd[u];i;i=nxt[i]) {
		int nx = to[i];
		if(d[nx]) continue;
		chd[u]++;
		fa[nx]=u;
		d[nx]=d[u]+1;
		dfs(nx);
	}
	return;
}
int main() {
	scanf("%d",&n);
	for(register int i = 1;i<n;++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	d[1]=fa[1]=1;
	dfs(1);
#ifdef DEBUG
	for(register int i  = 1;i<=n;++i) printf("%d ",d[i]);
	puts("");
#endif
	for(register int i = 1;i<=n;++i) num[d[i]]+=1;
	head=tail=1;
	queue[tail]=1;cnt[1]=1;
	int ign;
	scanf("%d",&ign);
	if(ign!=1) {
		printf("%d\n",ign);
		return 0;
	}
	for(register int i = 2;i<=n;++i) {
		int u;
		scanf("%d",&u);
		cnt[d[u]]++;
		if(d[u]>d[queue[head]]) {
			if(d[u]!=d[queue[head]]+1) {
				puts("No");
				return 0;
			}
			if(fa[u]==queue[head]) {
				chd[queue[head]]--;
				if(chd[queue[head]]==0) head++;
			}
			else {
#ifdef DEBUG
				printf("%d\n",i);
#endif
				puts("No");
				return 0;
			}
		}
		queue[++tail]=u;
	}
	for(register int i = 1;i<=n;++i)
		if(num[i]!=cnt[i]) {
#ifdef DEBUG
			puts("Err 2");
			printf("%d\n%d %d\n",i,num[i],cnt[i]);
#endif
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}


#include<iostream>
#include<set>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 200010;
int n,vis[maxn];
queue<int> order,Q;
set<int> V;
vector<int> G[maxn];
int main() {
	ios::sync_with_stdio(false);
	cin>>n;
	for(register int i = 1;i<n;++i) {
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(register int i = 1;i<=n;++i) {
		int t;
		cin>>t;
		order.push(t);
	}
	Q.push(1);vis[1]=1;
	if(order.front()!=1) {
		cout<<"No"<<endl;
		return 0;
	}
	order.pop();
	while(!Q.empty()) {
		int u = Q.front();Q.pop();
		vis[u]=1;
		for(auto x : G[u]) {
			if(vis[x]) continue;
			V.insert(x);
		}
		while(!V.empty()) {
			if(V.count(order.front())) {
				V.erase(order.front());
				order.pop();
			} else {
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


#include<iostream>
#include<set>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 200010;
int n,vis[maxn];
queue<int> order,Q;
set<int> V;
vector<int> G[maxn];
int main() {
	ios::sync_with_stdio(false);
	cin>>n;
	for(register int i = 1;i<n;++i) {
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(register int i = 1;i<=n;++i) {
		int t;
		cin>>t;
		order.push(t);
	}
	Q.push(1);vis[1]=1;
	if(order.front()!=1) {
		cout<<"No"<<endl;
		return 0;
	}
	order.pop();
	while(!Q.empty()) {
		int u = Q.front();Q.pop();
		vis[u]=1;
		for(auto x : G[u]) {
			if(vis[x]) continue;
			V.insert(x);
		}
		while(!V.empty()) {
			if(V.count(order.front())) {
				V.erase(order.front());
				Q.push(order.front());
				order.pop();
			} else {
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}
//123


#include<cstdio>//CF1037D
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>

using namespace std;

const int N=200010,NN=400020;

struct interval{
    int l,r;
};

int fr[N],edge[NN],nxt[NN],n,dep[N],vis[N],app[N],a[N],fa[N],dy[N];

interval il[N];

queue<int>q;

void bfs(){
    q.push(1);
    dep[1]=1;
    int u;
    while(!q.empty()){
        u=q.front();
        vis[u]=1;
        q.pop();
        int now=fr[u],v;
        while(now){
            v=edge[now];
            if(!vis[v]){
                dep[v]=dep[u]+1;
                fa[v]=u;
                q.push(v);
                il[u].l=min(il[u].l,dy[v]);
                il[u].r=max(il[u].r,dy[v]);
            }
            now=nxt[now];
        }
    }
}

bool check(){
    if(a[1]!=1){
        return false;
    }
    int nowdep;
    for(int i=1;i<=n;i++){
        if(dep[a[i]]<nowdep||app[a[i]]){
            return false;
        }
        else{
            app[a[i]]=1;
            nowdep=dep[a[i]];
        }
    }
    int tr=1;
    for(int i=1;i<=n;i++){
        if(il[a[i]].l==200010){
            continue;
        }
        if(il[a[i]].l>tr){
            tr=il[a[i]].r;
        }
        else{
            return false;
        }
    }
    return true;
}

int main(){
    scanf("%d",&n);
    int u,v;
    for(int i=1;i<=n;i++){
        il[i].l=200010;
        il[i].r=0;
    }
    for(int i=1;i<n;i++){
        int j=i+n;
        scanf("%d%d",&u,&v);
        edge[i]=v;
        nxt[i]=fr[u];
        fr[u]=i;
        edge[j]=u;
        nxt[j]=fr[v];
        fr[v]=j;
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        dy[a[i]]=i;
    }
    bfs();
    if(check()){
        printf("Yes\n");
        return 0;
    }
    else{
        printf("No\n");
        return 0;
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
const int maxn = 200010;
int n,nxt[maxn],to[maxn],hd[maxn],fa[maxn],tot=0,d[maxn],num[maxn],cnt[maxn],chd[maxn];
int queue[maxn],head,tail;
inline void add(int a,int b) {
	nxt[++tot]=hd[a];
	hd[a]=tot;
	to[tot]=b;
	return;
}
inline void dfs(int u) {
	for(register int i = hd[u];i;i=nxt[i]) {
		int nx = to[i];
		if(d[nx]) continue;
		chd[u]++;
		fa[nx]=u;
		d[nx]=d[u]+1;
		dfs(nx);
	}
	return;
}
int main() {
	scanf("%d",&n);
	for(register int i = 1;i<n;++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	d[1]=fa[1]=1;
	dfs(1);
#ifdef DEBUG
	for(register int i  = 1;i<=n;++i) printf("%d ",d[i]);
	puts("");
#endif
	for(register int i = 1;i<=n;++i) num[d[i]]+=1;
	head=tail=1;
	queue[tail]=1;cnt[1]=1;
	int ign;
	scanf("%d",&ign);
	if(ign!=1) {
		scanf("%d",&ign);
		printf("%d",ign);
		return 0;
	}
	for(register int i = 2;i<=n;++i) {
		int u;
		scanf("%d",&u);
		cnt[d[u]]++;
		if(d[u]>d[queue[head]]) {
			if(d[u]!=d[queue[head]]+1) {
				puts("No");
				return 0;
			}
			if(fa[u]==queue[head]) {
				chd[queue[head]]--;
				if(chd[queue[head]]==0) head++;
			}
			else {
#ifdef DEBUG
				printf("%d\n",i);
#endif
				puts("No");
				return 0;
			}
		}
		queue[++tail]=u;
	}
	for(register int i = 1;i<=n;++i)
		if(num[i]!=cnt[i]) {
#ifdef DEBUG
			puts("Err 2");
			printf("%d\n%d %d\n",i,num[i],cnt[i]);
#endif
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}


#include<cstdio>
#include<algorithm>
const int maxn = 200010;
int n,nxt[maxn],to[maxn],hd[maxn],fa[maxn],tot=0,d[maxn],num[maxn],cnt[maxn],chd[maxn];
int queue[maxn],head,tail;
inline void add(int a,int b) {
	nxt[++tot]=hd[a];
	hd[a]=tot;
	to[tot]=b;
	return;
}
inline void dfs(int u) {
	for(register int i = hd[u];i;i=nxt[i]) {
		int nx = to[i];
		if(d[nx]) continue;
		chd[u]++;
		fa[nx]=u;
		d[nx]=d[u]+1;
		dfs(nx);
	}
	return;
}
int main() {
	scanf("%d",&n);
	for(register int i = 1;i<n;++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	d[1]=fa[1]=1;
	dfs(1);
#ifdef DEBUG
	for(register int i  = 1;i<=n;++i) printf("%d ",d[i]);
	puts("");
#endif
	for(register int i = 1;i<=n;++i) num[d[i]]+=1;
	head=tail=1;
	queue[tail]=1;cnt[1]=1;
	int ign;
	scanf("%d",&ign);
	for(register int i = 2;i<=n;++i) {
		int u;
		scanf("%d",&u);
		cnt[d[u]]++;
		if(d[u]>d[queue[head]]) {
			if(d[u]!=d[queue[head]]+1) {
				puts("No");
				return 0;
			}
			if(fa[u]==queue[head]) {
				chd[queue[head]]--;
				if(chd[queue[head]]==0) head++;
			}
			else {
#ifdef DEBUG
				printf("%d\n",i);
#endif
				puts("No");
				return 0;
			}
		}
		queue[++tail]=u;
	}
	for(register int i = 1;i<=n;++i)
		if(num[i]!=cnt[i]) {
#ifdef DEBUG
			puts("Err 2");
			printf("%d\n%d %d\n",i,num[i],cnt[i]);
#endif
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}


#include<cstdio>
#include<algorithm>
const int maxn = 200010;
int n,nxt[maxn],to[maxn],hd[maxn],fa[maxn],tot=0,d[maxn],num[maxn],cnt[maxn],chd[maxn];
int queue[maxn],head,tail;
inline void add(int a,int b) {
	nxt[++tot]=hd[a];
	hd[a]=tot;
	to[tot]=b;
	return;
}
inline void dfs(int u) {
	for(register int i = hd[u];i;i=nxt[i]) {
		int nx = to[i];
		if(d[nx]) continue;
		chd[u]++;
		fa[nx]=u;
		d[nx]=d[u]+1;
		dfs(nx);
	}
	return;
}
int main() {
	scanf("%d",&n);
	for(register int i = 1;i<n;++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	d[1]=fa[1]=1;
	dfs(1);
#ifdef DEBUG
	for(register int i  = 1;i<=n;++i) printf("%d ",d[i]);
	puts("");
#endif
	for(register int i = 1;i<=n;++i) num[d[i]]+=1;
	head=tail=1;
	queue[tail]=1;cnt[1]=1;
	int ign;
	scanf("%d",&ign);
	if(ign!=1) {
		puts("No");
		return 0;
	}
	for(register int i = 2;i<=n;++i) {
		int u;
		scanf("%d",&u);
		cnt[d[u]]++;
		if(d[u]>d[queue[head]]) {
			if(d[u]!=d[queue[head]]+1) {
				puts("No");
				return 0;
			}
			if(fa[u]==queue[head]) {
				chd[queue[head]]--;
				if(chd[queue[head]]==0) head++;
			}
			else {
#ifdef DEBUG
				printf("%d\n",i);
#endif
				puts("No");
				return 0;
			}
		}
		queue[++tail]=u;
	}
	for(register int i = 1;i<=n;++i)
		if(num[i]!=cnt[i]) {
#ifdef DEBUG
			puts("Err 2");
			printf("%d\n%d %d\n",i,num[i],cnt[i]);
#endif
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}


#include<cstdio>
#include<cstring>
const int maxn = 200010;
int n,nxt[maxn],to[maxn],hd[maxn],tot=0,d[maxn],mx=0;
inline void add(int a,int b) {
	nxt[++tot]=hd[a];
	hd[a]=tot;
	to[tot]=b;
	return;
}
inline void dfs(int u) {
	for(register int i = hd[u];i;i=nxt[i]) {
		int nx = to[i];
		if(d[nx]) continue;
		d[nx]=d[u]+1;
		dfs(nx);
	}
	return;
}
int main() {
	scanf("%d",&n);
	int a,b;
	for(register int i = 1;i<n;++i) {
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	memset(d,0,sizeof d);
	d[1]=1;
	dfs(1);
	for(register int i = 1;i<=n;++i) {
		scanf("%d",&a);
		if(d[a]<mx) {
			puts("No");
			return 0;
		}
		if(d[a]>mx) mx=d[a];
	}
	puts("Yes");
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
const ll oo=1e18,sz=2e5+1;

vector<int>from(sz),to(sz);
vector<int>v;
bool check_bfs(vector<int>v){
    if(v[0]!=1)return false;
    queue<int>q;
    q.push(1);
    int index=1;
    while (q.size()){if(to[q.front()]&&index==v.size())return false;
       while(index<v.size()&&from[v[index]]==q.front()){

        q.push(v[index]);
        index++;
       }

       q.pop();
    }

    if(index!=v.size())return false;
    else return true;

}
int main(){
    int n;
    cin>>n;
    for(int x=1;x<n;x++){
        int z,y;
        cin>>z>>y;
        from[y]=z,to[z]=y;
    }
    while (n--){
        int y;
        cin>>y;
        v.push_back(y);
    }
    if(check_bfs(v))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
const ll oo=1e18,sz=2e5+1;

vector<int>from(sz),to(sz);
vector<int>v;
bool check_bfs(vector<int>v){
    if(v[0]!=1)return false;
    queue<int>q;
    q.push(1);
    int index=1;
    while (q.size()){if(to[q.front()]&&index==v.size())return false;
       while(index<v.size()&&from[v[index]]==q.front()){

        q.push(v[index]);
        index++;
       }

       q.pop();
    }

    if(index!=v.size())return false;
    else return true;

}
int main(){
    int n;
    cin>>n;
    for(int x=1;x<n;x++){
        int z,y;
        cin>>z>>y;
       if(from[y]||y==1)swap(z,y);
        from[y]=z,to[z]=y;
    }

    while (n--){
        int y;
        cin>>y;
        v.push_back(y);
    }
    if(check_bfs(v))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
const ll oo=1e18,sz=2e5+1;

vector<vector<int>>adj(sz);
vector<bool>vis(sz);
vector<int>from(sz),to(sz);
vector<int>v;
void build_tree(int t){
vis[t]=true;
for(auto f:adj[t]){
    if(!vis[f]){
            to[t]=f;
    from[f]=t;
        build_tree(f);
    }

}

}
bool check_bfs(vector<int>v){
    if(v[0]!=1)return false;
    queue<int>q;
    q.push(1);
    int index=1;
    while (q.size()){if(to[q.front()]&&index==v.size())return false;
       while(index<v.size()&&from[v[index]]==q.front()){

        q.push(v[index]);
        index++;
       }

       q.pop();
    }

    if(index!=v.size())return false;
    else return true;

}
int main(){
    int n;
    cin>>n;
    for(int x=1;x<n;x++){
        int z,y;
        cin>>z>>y;
       adj[z].push_back(y),adj[y].push_back(z);
    }

    while (n--){
        int y;
        cin>>y;
        v.push_back(y);
    }
    build_tree(1);

    if(check_bfs(v))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
const ll oo=1e18,sz=2e5+1;

vector<int>from(sz),to(sz);
vector<int>v;
bool check_bfs(vector<int>v){
    if(v[0]!=1)return false;
    queue<int>q;
    q.push(1);
    int index=1;
    while (q.size()){if(to[q.front()]&&index==v.size())return false;
       while(index<v.size()&&from[v[index]]==q.front()){

        q.push(v[index]);
        index++;
       }

       q.pop();
    }

    if(index!=v.size())return false;
    else return true;

}
int main(){
    int n;
    cin>>n;
    for(int x=1;x<n;x++){
        int z,y;
        cin>>z>>y;
       if(from[y])swap(z,y);
        from[y]=z,to[z]=y;
    }

    while (n--){
        int y;
        cin>>y;
        v.push_back(y);
    }
    if(check_bfs(v))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
const ll oo=1e18,sz=2e5+1;

vector<bool>vis(sz);
vector<int>from(sz);
vector<int>v;
bool check_bfs(vector<int>v){
    if(v[0]!=1)return false;
    queue<int>q;
    q.push(1);
    int index=1;
    while (q.size()){
       while(index<v.size()&&from[v[index]]==q.front()){

        q.push(v[index]);
        index++;
       }
      // debug(q.front());
       q.pop();
    }
    if(index!=v.size())return false;
    else return true;

}
int main(){
    int n;
    cin>>n;
    for(int x=1;x<n;x++){
        int z,y;
        cin>>z>>y;
        from[y]=z;
    }
    while (n--){
        int y;
        cin>>y;
        v.push_back(y);
    }
    if(check_bfs(v))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
const ll oo=1e18,sz=2e5+1;

vector<bool>vis(sz);
vector<int>from(sz);
vector<int>v;
bool check_bfs(vector<int>v){
    if(v[0]!=1)return false;
    queue<int>q;
    q.push(1);
    int index=1;
    while (q.size()&&index<v.size()){
       while(index<v.size()&&from[v[index]]==q.front()){

        q.push(v[index]);
        index++;
       }
      // debug(q.front());
       q.pop();
    }
    if(index!=v.size()||q.size())return false;
    else return true;

}
int main(){
    int n;
    cin>>n;
    for(int x=1;x<n;x++){
        int z,y;
        cin>>z>>y;
        from[y]=z;
    }
    while (n--){
        int y;
        cin>>y;
        v.push_back(y);
    }
    if(check_bfs(v))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
const ll oo=1e18,sz=2e5+1;

vector<bool>vis(sz);
vector<int>from(sz);
vector<int>v;
bool check_bfs(vector<int>v){
    if(v[0]!=1)return false;
    queue<int>q;
    q.push(1);
    int index=1;
    while (q.size()&&index<v.size()){
       while(index<v.size()&&from[v[index]]==q.front()){

        q.push(v[index]);
        index++;
       }
      // debug(q.front());
       q.pop();
    }
    if(index!=v.size())return false;
    else return true;

}
int main(){
    int n;
    cin>>n;
    for(int x=1;x<n;x++){
        int z,y;
        cin>>z>>y;
        from[y]=z;
    }
    while (n--){
        int y;
        cin>>y;
        v.push_back(y);
    }
    if(check_bfs(v))cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==0){
        cout<<"No";
        return 0;
    }
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    }
   x=target.front();
    target.pop_front();
    unordered_set<int>used;
    used.insert(x);
    queue<int>q;
    q.push(x);
    while(!q.empty())
    {
        int s=q.size();
        unordered_set<int>level;
        while(s--)
        {
            x=q.front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                    level.insert(i);
                }
            }
        }
        while(!level.empty() && !target.empty())
        {
            y=target.front();
            if(level.count(y)==0){
                cout<<"No";
                return 0;
            }
            else
            {
                target.pop_front();
                level.erase(y);
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>pos(200007,0);

      bool what(int &a,int &b)
{
    return pos[a]<pos[b];
}

int main()
{
    int n;
    cin>>n;
    if(n==0){
        cout<<"No";
        return 0;
    }
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
    }
    list<int>target;

    for(int i=1;i<=n;i++)
    {cin>>x;
    target.push_back(x);
    pos[x]=i;
    }

   for(vector<int> v:graph)
   {
       if(v.size()>0)
       sort(v.begin(),v.end(),what);
   }
  // cout<<"1: "<<graph[1][0]<< " "<<graph[1][1]<<endl;
    unordered_set<int>used;
    used.insert(1);
    queue<int>q;
    q.push(1);
    while(!q.empty() && !target.empty())
    {
        int s=q.size();
        while(s-- && !target.empty())
        {
            y=target.front();
            x=q.front();
           // cout<<"x= "<<x<<" and y= "<<y<<endl;
            if(y!=x){
                cout<<"No";
                return 0;
            }
            target.pop_front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                }
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    }
    if(target.front()!=1){cout<<"No";return 0;}

    target.pop_front();
    unordered_set<int>used;
    used.insert(1);
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int s=q.size();
        unordered_set<int>level;
        while(s--)
        {
            x=q.front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                    level.insert(i);
                }
            }
        }
        while(!level.empty() && !target.empty())
        {
            y=target.front();
            if(level.count(y)==0){
                cout<<"No";
                return 0;
            }
            else
            {
                target.pop_front();
                level.erase(y);
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    }
    x=target.front();
    target.pop_front();
    unordered_set<int>used;
    used.insert(x);
    queue<int>q;
    q.push(x);
    while(!q.empty())
    {
        int s=q.size();
        unordered_set<int>level;
        while(s--)
        {
            x=q.front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                    level.insert(i);
                }
            }
        }
        while(!level.empty() && !target.empty())
        {
            y=target.front();
            if(level.count(y)==0){
                cout<<"No";
                return 0;
            }
            else
            {
                target.pop_front();
                level.erase(y);
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
unordered_map<int,int>pos;
bool comp(int a, int b)
{
    return (pos[a]<pos[b]);
}
int main()
{
    int n;
    cin>>n;
    if(n==0){
        cout<<"No";
        return 0;
    }
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    pos[x]=i;
    }

   for(int i=1;i<=n;i++)
   {
       sort(graph[i].begin(),graph[i].end(),comp);
   }
    unordered_set<int>used;
    used.insert(1);
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int s=q.size();
        while(s-- && !target.empty())
        {
            y=target.front();
            x=q.front();
            if(y!=x){
                cout<<"No";
                return 0;
            }
            target.pop_front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                }
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    }
   x=target.front();
    target.pop_front();
    unordered_set<int>used;
    used.insert(x);
    queue<int>q;
    q.push(x);
    while(!q.empty())
    {
        int s=q.size();
        unordered_set<int>level;
        while(s--)
        {
            x=q.front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                    level.insert(i);
                }
            }
        }
        while(!level.empty() && !target.empty())
        {
            y=target.front();
            if(level.count(y)==0){
                cout<<"No";
                return 0;
            }
            else
            {
                target.pop_front();
                level.erase(y);
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
unordered_map<int,int>pos;
bool comp(int a, int b)
{
    return (pos[a]<pos[b]);
}
int main()
{
    int n;
    cin>>n;
    if(n==0){
        cout<<"No";
        return 0;
    }
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    pos[x]=i;
    }

   for(auto v:graph)
   {
       sort(v.begin(),v.end(),comp);
   }
    unordered_set<int>used;
    used.insert(1);
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int s=q.size();
        while(s-- && !target.empty())
        {
            y=target.front();
            x=q.front();
            if(y!=x){
                cout<<"No";
                return 0;
            }
            target.pop_front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                }
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==0){
        cout<<"No";
        return 0;
    }
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    }
   x=target.front();
   if(x!=1){
       cout<<"No";
       return 0;
   }
    target.pop_front();
    unordered_set<int>used;
    used.insert(1);
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int s=q.size();
        unordered_set<int>level;
        while(s--)
        {
            x=q.front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                    level.insert(i);
                }
            }
        }
        while(!level.empty())
        {
            if(target.empty()||level.count(target.front())==0){
                cout<<"No";
                return 0;
            }
            else
            {
                y=target.front();
                target.pop_front();
                level.erase(y);
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
unordered_map<int,int>pos;
bool comp(int a, int b)
{
    return (pos[a]<pos[b]);
}
int main()
{
    int n;
    cin>>n;
    if(n==0){
        cout<<"No";
        return 0;
    }
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    pos[x]=i;
    }

   for(int i=1;i<=n;i++)
   {
       sort(graph[i].begin(),graph[i].end(),comp);
   }
    unordered_set<int>used;
    used.insert(1);
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int s=q.size();
        while(s-- && !target.empty())
        {
            y=target.front();
            x=q.front();
            if(y!=x){
                cout<<"No";
                return 0;
            }
            target.pop_front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                }
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==0){
        cout<<"No";
        return 0;
    }
    int x,y;
    vector<vector<int>>graph(n+1,vector<int>());
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    list<int>target;

    for(int i=0;i<n;i++)
    {cin>>x;
    target.push_back(x);
    }
   x=target.front();
   if(x!=1){
       cout<<"No";
       return 0;
   }
    target.pop_front();
    unordered_set<int>used;
    used.insert(1);
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int s=q.size();
        unordered_set<int>level;
        while(s--)
        {
            x=q.front();
            q.pop();
            for(int i: graph[x])
            {
                if(used.count(i)==0)
                {
                    used.insert(i);
                    q.push(i);
                    level.insert(i);
                }
            }
        }
        while(!level.empty() && !target.empty())
        {
            y=target.front();
            if(level.count(y)==0){
                cout<<"No";
                return 0;
            }
            else
            {
                target.pop_front();
                level.erase(y);
            }
        }

    }
    cout<<"Yes";
        return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define loop() int t;cin>>t;while(t--)
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define um unordered_map<ll,ll>
#define mll map<ll,ll>
#define pq priority_queue<ll>
#define pql priority_queue<ll,vector<ll>,greater<ll>>

#define fr(i,b) for(i=0;i<b;i++)
#define fri(i,a,b) for(i=a;i<b;i++)

#define il(a) long long a;cin>>a;
#define il2(a,b) long long a,b;cin>>a>>b;
#define il3(a,b,c) long long a,b,c;cin>>a>>b>>c;
#define il4(a,b,c,d) long long a,b,c,d;cin>>a>>b>>c>>d;
#define il5(a,b,c,d,e) long long a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define id(a) double a;cin>>a;
#define id2(a,b) double a,b;cin>>a>>b;
#define id3(a,b,c) double a,b,c;cin>>a>>b>>c;
#define id4(a,b,c,d) double a,b,c,d;cin>>a>>b>>c>>d;
#define id5(a,b,c,d,e) double a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define ia(a,n) vll a(n);for( i=0;i<n;i++) cin>>a[i];
#define ian(a,n) ll n;cin>>n;vl a(n+3);for(ll i=0;i<n;++i)cin>>a[i];
#define ia2(a,m,n) ll m,n;cin>>m>>n;ll a[m+4][n+4];for(ll i=0;i<m;++i)for(ll j=0;j<n;++j)cin>>a[i][j];
#define is(s,n) string s;cin>>s;ll n;n=s.size();

#define pa(a,n) for(ll i=0;i<n;++i) cout<<a[i]<<" ";cout<<endl;
#define pa2(a,m,n) for(ll i=0;i<m;++i){for(ll j=0;j<n;++j)cout<<a[i][j]<<" ";cout<<endl;}
#define pd(z,k) cout<<fixed<<setprecision(k)<<z<<endl;

#define pb push_back
#define mp make_pair
#define all(c)    (c).begin(),(c).end()
#define allr(c)   (c).rbegin(),(c).rend()
#define ST(c)    sort((c).begin(),(c).end())
#define lb(c,x) lower_bound(all(c),x)-c.begin()
#define up(c,x) upper_bound(all(c),x)-c.begin()
#define F first
#define S second
#define mem(x,val) memset(x,val,sizeof(x))
#define v2d(type,v,m,n,val) vector<vector<type>>v(m,vector<type>(n,val));

#define spresent(c,x)    ((c).find(x) != (c).end())
#define present(c,x)   (find(all(c),x) != (c).end())
#define count1(a)    __builtin_popcountll(a)
#define power2(a)      (a)&(a-1)==0
#define sz(a)           (ll)((a).size())
#define mod 1000000007
//onst long long mod = 1e9+7;
const long long M = 1e6+5;
const double pi=acos(-1.);
const long long dx[]={1,0,-1,0,-1,-1,1,1};
const long long dy[]={0,1,0,-1,1,-1,1,-1};

long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,maxi,mini,ans,mid,low,high,sum,total;
string s1,s2;
/*
int cmp(pll a,pll b)
{
	if(a.first < b.first)
	return 1;
	else if(a.first==b.first)
	{
		if(a.second > b.second)
		return 1;
		return 0;
	}
	return 0;
}*/

/*void seive()
{
	for(i=2;i<=1000000000;i++)
	{
		if(prime[i])
		{
			for(j=2*i;j<=1000000000;j++)
			{
				factor[j].pb(i);
			}
		}
	}
}*/
//int dp[5001][5001];

int main()
{
	map<ll,ll>m;
	queue<int>q;

	cin>>n;
	vll v[n+1];

	fr(i,n-1)
	{
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}

	ia(a,n);
	if(a[0]!=1)
	{
	    cout<<"No";
	    return 0;
	}
	q.push(a[0]);
	p=a[0];

	m[a[0]]++;

	if(v[1].size()==n-1)
	{
	    cout<<"Yes";
	    return 0;
	}

	for(i=1;i<n;i++)
	{
		while(find(all(v[p]),a[i])==v[p].end() && !q.empty() )
		{
			q.pop();
			if(!q.empty())
			p=q.front();
		}

		if(find(all(v[p]),a[i])==v[p].end())
		break;

		q.push(a[i]);
		m[a[i]]++;
	}

	if(m.size()==n)
	cout<<"Yes";
	else
	cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;

#define loop() int t;cin>>t;while(t--)
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define um unordered_map<ll,ll>
#define mll map<ll,ll>
#define pq priority_queue<ll>
#define pql priority_queue<ll,vector<ll>,greater<ll>>

#define fr(i,b) for(i=0;i<b;i++)
#define fri(i,a,b) for(i=a;i<b;i++)

#define il(a) long long a;cin>>a;
#define il2(a,b) long long a,b;cin>>a>>b;
#define il3(a,b,c) long long a,b,c;cin>>a>>b>>c;
#define il4(a,b,c,d) long long a,b,c,d;cin>>a>>b>>c>>d;
#define il5(a,b,c,d,e) long long a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define id(a) double a;cin>>a;
#define id2(a,b) double a,b;cin>>a>>b;
#define id3(a,b,c) double a,b,c;cin>>a>>b>>c;
#define id4(a,b,c,d) double a,b,c,d;cin>>a>>b>>c>>d;
#define id5(a,b,c,d,e) double a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define ia(a,n) vll a(n);for( i=0;i<n;i++) cin>>a[i];
#define ian(a,n) ll n;cin>>n;vl a(n+3);for(ll i=0;i<n;++i)cin>>a[i];
#define ia2(a,m,n) ll m,n;cin>>m>>n;ll a[m+4][n+4];for(ll i=0;i<m;++i)for(ll j=0;j<n;++j)cin>>a[i][j];
#define is(s,n) string s;cin>>s;ll n;n=s.size();

#define pa(a,n) for(ll i=0;i<n;++i) cout<<a[i]<<" ";cout<<endl;
#define pa2(a,m,n) for(ll i=0;i<m;++i){for(ll j=0;j<n;++j)cout<<a[i][j]<<" ";cout<<endl;}
#define pd(z,k) cout<<fixed<<setprecision(k)<<z<<endl;

#define pb push_back
#define mp make_pair
#define all(c)    (c).begin(),(c).end()
#define allr(c)   (c).rbegin(),(c).rend()
#define ST(c)    sort((c).begin(),(c).end())
#define lb(c,x) lower_bound(all(c),x)-c.begin()
#define up(c,x) upper_bound(all(c),x)-c.begin()
#define F first
#define S second
#define mem(x,val) memset(x,val,sizeof(x))
#define v2d(type,v,m,n,val) vector<vector<type>>v(m,vector<type>(n,val));

#define spresent(c,x)    ((c).find(x) != (c).end())
#define present(c,x)   (find(all(c),x) != (c).end())
#define count1(a)    __builtin_popcountll(a)
#define power2(a)      (a)&(a-1)==0
#define sz(a)           (ll)((a).size())
#define mod 1000000007
//onst long long mod = 1e9+7;
const long long M = 1e6+5;
const double pi=acos(-1.);
const long long dx[]={1,0,-1,0,-1,-1,1,1};
const long long dy[]={0,1,0,-1,1,-1,1,-1};

long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,maxi,mini,ans,mid,low,high,sum,total;
string s1,s2;
/*
int cmp(pll a,pll b)
{
	if(a.first < b.first)
	return 1;
	else if(a.first==b.first)
	{
		if(a.second > b.second)
		return 1;
		return 0;
	}
	return 0;
}*/

/*void seive()
{
	for(i=2;i<=1000000000;i++)
	{
		if(prime[i])
		{
			for(j=2*i;j<=1000000000;j++)
			{
				factor[j].pb(i);
			}
		}
	}
}*/
//int dp[5001][5001];

int main()
{
	map<ll,ll>m;
	queue<int>q;

	cin>>n;
	vll v[n+1];

	fr(i,n-1)
	{
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}

	ia(a,n);

	q.push(a[0]);
	p=a[0];

	m[a[0]]++;

	for(i=1;i<n;i++)
	{

		while(find(all(v[p]),a[i])==v[p].end() && !q.empty() )
		{
			q.pop();
			if(!q.empty())
			p=q.front();
		}

		if(find(all(v[p]),a[i])==v[p].end())
		break;

		q.push(a[i]);
		m[a[i]]++;
	}

	if(m.size()==n)
	cout<<"Yes";
	else
	cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;

#define loop() int t;cin>>t;while(t--)
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define um unordered_map<ll,ll>
#define mll map<ll,ll>
#define pq priority_queue<ll>
#define pql priority_queue<ll,vector<ll>,greater<ll>>

#define fr(i,b) for(i=0;i<b;i++)
#define fri(i,a,b) for(i=a;i<b;i++)

#define il(a) long long a;cin>>a;
#define il2(a,b) long long a,b;cin>>a>>b;
#define il3(a,b,c) long long a,b,c;cin>>a>>b>>c;
#define il4(a,b,c,d) long long a,b,c,d;cin>>a>>b>>c>>d;
#define il5(a,b,c,d,e) long long a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define id(a) double a;cin>>a;
#define id2(a,b) double a,b;cin>>a>>b;
#define id3(a,b,c) double a,b,c;cin>>a>>b>>c;
#define id4(a,b,c,d) double a,b,c,d;cin>>a>>b>>c>>d;
#define id5(a,b,c,d,e) double a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define ia(a,n) vll a(n);for( i=0;i<n;i++) cin>>a[i];
#define ian(a,n) ll n;cin>>n;vl a(n+3);for(ll i=0;i<n;++i)cin>>a[i];
#define ia2(a,m,n) ll m,n;cin>>m>>n;ll a[m+4][n+4];for(ll i=0;i<m;++i)for(ll j=0;j<n;++j)cin>>a[i][j];
#define is(s,n) string s;cin>>s;ll n;n=s.size();

#define pa(a,n) for(ll i=0;i<n;++i) cout<<a[i]<<" ";cout<<endl;
#define pa2(a,m,n) for(ll i=0;i<m;++i){for(ll j=0;j<n;++j)cout<<a[i][j]<<" ";cout<<endl;}
#define pd(z,k) cout<<fixed<<setprecision(k)<<z<<endl;

#define pb push_back
#define mp make_pair
#define all(c)    (c).begin(),(c).end()
#define allr(c)   (c).rbegin(),(c).rend()
#define ST(c)    sort((c).begin(),(c).end())
#define lb(c,x) lower_bound(all(c),x)-c.begin()
#define up(c,x) upper_bound(all(c),x)-c.begin()
#define F first
#define S second
#define mem(x,val) memset(x,val,sizeof(x))
#define v2d(type,v,m,n,val) vector<vector<type>>v(m,vector<type>(n,val));

#define spresent(c,x)    ((c).find(x) != (c).end())
#define present(c,x)   (find(all(c),x) != (c).end())
#define count1(a)    __builtin_popcountll(a)
#define power2(a)      (a)&(a-1)==0
#define sz(a)           (ll)((a).size())
#define mod 1000000007
//onst long long mod = 1e9+7;
const long long M = 1e6+5;
const double pi=acos(-1.);
const long long dx[]={1,0,-1,0,-1,-1,1,1};
const long long dy[]={0,1,0,-1,1,-1,1,-1};

long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,maxi,mini,ans,mid,low,high,sum,total;
string s1,s2;
/*
int cmp(pll a,pll b)
{
	if(a.first < b.first)
	return 1;
	else if(a.first==b.first)
	{
		if(a.second > b.second)
		return 1;
		return 0;
	}
	return 0;
}*/

/*void seive()
{
	for(i=2;i<=1000000000;i++)
	{
		if(prime[i])
		{
			for(j=2*i;j<=1000000000;j++)
			{
				factor[j].pb(i);
			}
		}
	}
}*/
//int dp[5001][5001];

int main()
{
	map<ll,ll>m;
	queue<int>q;

	cin>>n;
	vll v[n+1];

	fr(i,n-1)
	{
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}

	ia(a,n);
	if(a[0]!=0)
	{
	    cout<<"No";
	    return 0;
	}
	q.push(a[0]);
	p=a[0];

	m[a[0]]++;

	for(i=1;i<n;i++)
	{

		while(find(all(v[p]),a[i])==v[p].end() && !q.empty() )
		{
			q.pop();
			if(!q.empty())
			p=q.front();
		}

		if(find(all(v[p]),a[i])==v[p].end())
		break;

		q.push(a[i]);
		m[a[i]]++;
	}

	if(m.size()==n)
	cout<<"Yes";
	else
	cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;

#define loop() int t;cin>>t;while(t--)
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define um unordered_map<ll,ll>
#define mll map<ll,ll>
#define pq priority_queue<ll>
#define pql priority_queue<ll,vector<ll>,greater<ll>>

#define fr(i,b) for(i=0;i<b;i++)
#define fri(i,a,b) for(i=a;i<b;i++)

#define il(a) long long a;cin>>a;
#define il2(a,b) long long a,b;cin>>a>>b;
#define il3(a,b,c) long long a,b,c;cin>>a>>b>>c;
#define il4(a,b,c,d) long long a,b,c,d;cin>>a>>b>>c>>d;
#define il5(a,b,c,d,e) long long a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define id(a) double a;cin>>a;
#define id2(a,b) double a,b;cin>>a>>b;
#define id3(a,b,c) double a,b,c;cin>>a>>b>>c;
#define id4(a,b,c,d) double a,b,c,d;cin>>a>>b>>c>>d;
#define id5(a,b,c,d,e) double a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define ia(a,n) vll a(n);for( i=0;i<n;i++) cin>>a[i];
#define ian(a,n) ll n;cin>>n;vl a(n+3);for(ll i=0;i<n;++i)cin>>a[i];
#define ia2(a,m,n) ll m,n;cin>>m>>n;ll a[m+4][n+4];for(ll i=0;i<m;++i)for(ll j=0;j<n;++j)cin>>a[i][j];
#define is(s,n) string s;cin>>s;ll n;n=s.size();

#define pa(a,n) for(ll i=0;i<n;++i) cout<<a[i]<<" ";cout<<endl;
#define pa2(a,m,n) for(ll i=0;i<m;++i){for(ll j=0;j<n;++j)cout<<a[i][j]<<" ";cout<<endl;}
#define pd(z,k) cout<<fixed<<setprecision(k)<<z<<endl;

#define pb push_back
#define mp make_pair
#define all(c)    (c).begin(),(c).end()
#define allr(c)   (c).rbegin(),(c).rend()
#define ST(c)    sort((c).begin(),(c).end())
#define lb(c,x) lower_bound(all(c),x)-c.begin()
#define up(c,x) upper_bound(all(c),x)-c.begin()
#define F first
#define S second
#define mem(x,val) memset(x,val,sizeof(x))
#define v2d(type,v,m,n,val) vector<vector<type>>v(m,vector<type>(n,val));

#define spresent(c,x)    ((c).find(x) != (c).end())
#define present(c,x)   (find(all(c),x) != (c).end())
#define count1(a)    __builtin_popcountll(a)
#define power2(a)      (a)&(a-1)==0
#define sz(a)           (ll)((a).size())
#define mod 1000000007
//onst long long mod = 1e9+7;
const long long M = 1e6+5;
const double pi=acos(-1.);
const long long dx[]={1,0,-1,0,-1,-1,1,1};
const long long dy[]={0,1,0,-1,1,-1,1,-1};

long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,maxi,mini,ans,mid,low,high,sum,total;
string s1,s2;
/*
int cmp(pll a,pll b)
{
	if(a.first < b.first)
	return 1;
	else if(a.first==b.first)
	{
		if(a.second > b.second)
		return 1;
		return 0;
	}
	return 0;
}*/

/*void seive()
{
	for(i=2;i<=1000000000;i++)
	{
		if(prime[i])
		{
			for(j=2*i;j<=1000000000;j++)
			{
				factor[j].pb(i);
			}
		}
	}
}*/
//int dp[5001][5001];

int main()
{
	map<ll,ll>m;
	queue<int>q;

	cin>>n;
	int v[n+1][n+1];
	memset(v,0,sizeof(v));

	fr(i,n-1)
	{
		cin>>x>>y;
		v[x][y]=1;
		v[y][x]=1;
	}

	ia(a,n);

	q.push(a[0]);
	p=a[0];

	m[a[0]]++;

	for(i=1;i<n;i++)
	{

		while(v[p][a[i]]!=1 && !q.empty() )
		{
			q.pop();
			if(!q.empty())
			p=q.front();
		}

		if(v[p][a[i]]!=1)
		break;

		q.push(a[i]);
		m[a[i]]++;
	}

	if(m.size()==n)
	cout<<"Yes";
	else
	cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;

#define loop() int t;cin>>t;while(t--)
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define um unordered_map<ll,ll>
#define mll map<ll,ll>
#define pq priority_queue<ll>
#define pql priority_queue<ll,vector<ll>,greater<ll>>

#define fr(i,b) for(i=0;i<b;i++)
#define fri(i,a,b) for(i=a;i<b;i++)

#define il(a) long long a;cin>>a;
#define il2(a,b) long long a,b;cin>>a>>b;
#define il3(a,b,c) long long a,b,c;cin>>a>>b>>c;
#define il4(a,b,c,d) long long a,b,c,d;cin>>a>>b>>c>>d;
#define il5(a,b,c,d,e) long long a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define id(a) double a;cin>>a;
#define id2(a,b) double a,b;cin>>a>>b;
#define id3(a,b,c) double a,b,c;cin>>a>>b>>c;
#define id4(a,b,c,d) double a,b,c,d;cin>>a>>b>>c>>d;
#define id5(a,b,c,d,e) double a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define ia(a,n) vll a(n);for( i=0;i<n;i++) cin>>a[i];
#define ian(a,n) ll n;cin>>n;vl a(n+3);for(ll i=0;i<n;++i)cin>>a[i];
#define ia2(a,m,n) ll m,n;cin>>m>>n;ll a[m+4][n+4];for(ll i=0;i<m;++i)for(ll j=0;j<n;++j)cin>>a[i][j];
#define is(s,n) string s;cin>>s;ll n;n=s.size();

#define pa(a,n) for(ll i=0;i<n;++i) cout<<a[i]<<" ";cout<<endl;
#define pa2(a,m,n) for(ll i=0;i<m;++i){for(ll j=0;j<n;++j)cout<<a[i][j]<<" ";cout<<endl;}
#define pd(z,k) cout<<fixed<<setprecision(k)<<z<<endl;

#define pb push_back
#define mp make_pair
#define all(c)    (c).begin(),(c).end()
#define allr(c)   (c).rbegin(),(c).rend()
#define ST(c)    sort((c).begin(),(c).end())
#define lb(c,x) lower_bound(all(c),x)-c.begin()
#define up(c,x) upper_bound(all(c),x)-c.begin()
#define F first
#define S second
#define mem(x,val) memset(x,val,sizeof(x))
#define v2d(type,v,m,n,val) vector<vector<type>>v(m,vector<type>(n,val));

#define spresent(c,x)    ((c).find(x) != (c).end())
#define present(c,x)   (find(all(c),x) != (c).end())
#define count1(a)    __builtin_popcountll(a)
#define power2(a)      (a)&(a-1)==0
#define sz(a)           (ll)((a).size())
#define mod 1000000007
//onst long long mod = 1e9+7;
const long long M = 1e6+5;
const double pi=acos(-1.);
const long long dx[]={1,0,-1,0,-1,-1,1,1};
const long long dy[]={0,1,0,-1,1,-1,1,-1};

long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,maxi,mini,ans,mid,low,high,sum,total;
string s1,s2;
/*
int cmp(pll a,pll b)
{
	if(a.first < b.first)
	return 1;
	else if(a.first==b.first)
	{
		if(a.second > b.second)
		return 1;
		return 0;
	}
	return 0;
}*/

/*void seive()
{
	for(i=2;i<=1000000000;i++)
	{
		if(prime[i])
		{
			for(j=2*i;j<=1000000000;j++)
			{
				factor[j].pb(i);
			}
		}
	}
}*/
//int dp[5001][5001];

int main()
{
	map<ll,ll>m;
	queue<int>q;

	cin>>n;
	vll v[n+1];

	fr(i,n-1)
	{
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}

	ia(a,n);
	if(a[0]!=1)
	{
	    cout<<"No";
	    return 0;
	}
	q.push(a[0]);
	p=a[0];

	m[a[0]]++;

	for(i=1;i<n;i++)
	{

		while(find(all(v[p]),a[i])==v[p].end() && !q.empty() )
		{
			q.pop();
			if(!q.empty())
			p=q.front();
		}

		if(find(all(v[p]),a[i])==v[p].end())
		break;

		q.push(a[i]);
		m[a[i]]++;
	}

	if(m.size()==n)
	cout<<"Yes";
	else
	cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;

#define loop() int t;cin>>t;while(t--)
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define um unordered_map<ll,ll>
#define mll map<ll,ll>
#define pq priority_queue<ll>
#define pql priority_queue<ll,vector<ll>,greater<ll>>

#define fr(i,b) for(i=0;i<b;i++)
#define fri(i,a,b) for(i=a;i<b;i++)

#define il(a) long long a;cin>>a;
#define il2(a,b) long long a,b;cin>>a>>b;
#define il3(a,b,c) long long a,b,c;cin>>a>>b>>c;
#define il4(a,b,c,d) long long a,b,c,d;cin>>a>>b>>c>>d;
#define il5(a,b,c,d,e) long long a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define id(a) double a;cin>>a;
#define id2(a,b) double a,b;cin>>a>>b;
#define id3(a,b,c) double a,b,c;cin>>a>>b>>c;
#define id4(a,b,c,d) double a,b,c,d;cin>>a>>b>>c>>d;
#define id5(a,b,c,d,e) double a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define ia(a,n) vll a(n);for( i=0;i<n;i++) cin>>a[i];
#define ian(a,n) ll n;cin>>n;vl a(n+3);for(ll i=0;i<n;++i)cin>>a[i];
#define ia2(a,m,n) ll m,n;cin>>m>>n;ll a[m+4][n+4];for(ll i=0;i<m;++i)for(ll j=0;j<n;++j)cin>>a[i][j];
#define is(s,n) string s;cin>>s;ll n;n=s.size();

#define pa(a,n) for(ll i=0;i<n;++i) cout<<a[i]<<" ";cout<<endl;
#define pa2(a,m,n) for(ll i=0;i<m;++i){for(ll j=0;j<n;++j)cout<<a[i][j]<<" ";cout<<endl;}
#define pd(z,k) cout<<fixed<<setprecision(k)<<z<<endl;

#define pb push_back
#define mp make_pair
#define all(c)    (c).begin(),(c).end()
#define allr(c)   (c).rbegin(),(c).rend()
#define ST(c)    sort((c).begin(),(c).end())
#define lb(c,x) lower_bound(all(c),x)-c.begin()
#define up(c,x) upper_bound(all(c),x)-c.begin()
#define F first
#define S second
#define mem(x,val) memset(x,val,sizeof(x))
#define v2d(type,v,m,n,val) vector<vector<type>>v(m,vector<type>(n,val));

#define spresent(c,x)    ((c).find(x) != (c).end())
#define present(c,x)   (find(all(c),x) != (c).end())
#define count1(a)    __builtin_popcountll(a)
#define power2(a)      (a)&(a-1)==0
#define sz(a)           (ll)((a).size())
#define mod 1000000007
//onst long long mod = 1e9+7;
const long long M = 1e6+5;
const double pi=acos(-1.);
const long long dx[]={1,0,-1,0,-1,-1,1,1};
const long long dy[]={0,1,0,-1,1,-1,1,-1};

long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,maxi,mini,ans,mid,low,high,sum,total;
string s1,s2;
/*
int cmp(pll a,pll b)
{
	if(a.first < b.first)
	return 1;
	else if(a.first==b.first)
	{
		if(a.second > b.second)
		return 1;
		return 0;
	}
	return 0;
}*/

/*void seive()
{
	for(i=2;i<=1000000000;i++)
	{
		if(prime[i])
		{
			for(j=2*i;j<=1000000000;j++)
			{
				factor[j].pb(i);
			}
		}
	}
}*/
//int dp[5001][5001];

int main()
{
	map<ll,ll>m;
	queue<int>q;

	cin>>n;
	vll v[n+1];

	fr(i,n-1)
	{
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}

	ia(a,n);

	q.push(a[0]);
	p=a[0];

	m[a[0]]++;

	for(i=1;i<n;i++)
	{
		while(find(all(v[p]),a[i])==v[p].end() && !q.empty() )
		{
			q.pop();
			if(!q.empty())
			p=q.front();
		}

		if(find(all(v[p]),a[i])==v[p].end())
		break;

		q.push(a[i]);
		m[a[i]]++;
	}

	if(m.size()==n)
	cout<<"Yes";
	else
	cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;

#define loop() int t;cin>>t;while(t--)
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define um unordered_map<ll,ll>
#define mll map<ll,ll>
#define pq priority_queue<ll>
#define pql priority_queue<ll,vector<ll>,greater<ll>>

#define fr(i,b) for(i=0;i<b;i++)
#define fri(i,a,b) for(i=a;i<b;i++)

#define il(a) long long a;cin>>a;
#define il2(a,b) long long a,b;cin>>a>>b;
#define il3(a,b,c) long long a,b,c;cin>>a>>b>>c;
#define il4(a,b,c,d) long long a,b,c,d;cin>>a>>b>>c>>d;
#define il5(a,b,c,d,e) long long a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define id(a) double a;cin>>a;
#define id2(a,b) double a,b;cin>>a>>b;
#define id3(a,b,c) double a,b,c;cin>>a>>b>>c;
#define id4(a,b,c,d) double a,b,c,d;cin>>a>>b>>c>>d;
#define id5(a,b,c,d,e) double a,b,c,d,e;cin>>a>>b>>c>>d>>e;
#define ia(a,n) vll a(n);for( i=0;i<n;i++) cin>>a[i];
#define ian(a,n) ll n;cin>>n;vl a(n+3);for(ll i=0;i<n;++i)cin>>a[i];
#define ia2(a,m,n) ll m,n;cin>>m>>n;ll a[m+4][n+4];for(ll i=0;i<m;++i)for(ll j=0;j<n;++j)cin>>a[i][j];
#define is(s,n) string s;cin>>s;ll n;n=s.size();

#define pa(a,n) for(ll i=0;i<n;++i) cout<<a[i]<<" ";cout<<endl;
#define pa2(a,m,n) for(ll i=0;i<m;++i){for(ll j=0;j<n;++j)cout<<a[i][j]<<" ";cout<<endl;}
#define pd(z,k) cout<<fixed<<setprecision(k)<<z<<endl;

#define pb push_back
#define mp make_pair
#define all(c)    (c).begin(),(c).end()
#define allr(c)   (c).rbegin(),(c).rend()
#define ST(c)    sort((c).begin(),(c).end())
#define lb(c,x) lower_bound(all(c),x)-c.begin()
#define up(c,x) upper_bound(all(c),x)-c.begin()
#define F first
#define S second
#define mem(x,val) memset(x,val,sizeof(x))
#define v2d(type,v,m,n,val) vector<vector<type>>v(m,vector<type>(n,val));

#define spresent(c,x)    ((c).find(x) != (c).end())
#define present(c,x)   (find(all(c),x) != (c).end())
#define count1(a)    __builtin_popcountll(a)
#define power2(a)      (a)&(a-1)==0
#define sz(a)           (ll)((a).size())
#define mod 1000000007
//onst long long mod = 1e9+7;
const long long M = 1e6+5;
const double pi=acos(-1.);
const long long dx[]={1,0,-1,0,-1,-1,1,1};
const long long dy[]={0,1,0,-1,1,-1,1,-1};

long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,maxi,mini,ans,mid,low,high,sum,total;
string s1,s2;
/*
int cmp(pll a,pll b)
{
	if(a.first < b.first)
	return 1;
	else if(a.first==b.first)
	{
		if(a.second > b.second)
		return 1;
		return 0;
	}
	return 0;
}*/

/*void seive()
{
	for(i=2;i<=1000000000;i++)
	{
		if(prime[i])
		{
			for(j=2*i;j<=1000000000;j++)
			{
				factor[j].pb(i);
			}
		}
	}
}*/
//int dp[5001][5001];

int main()
{
	map<ll,ll>m;
	queue<int>q;

	cin>>n;
	int v[n+1][n+1];
	memset(v,0,sizeof(v));

	fr(i,n-1)
	{
		cin>>x>>y;
		v[x][y]=1;
		v[y][x]=1;
	}

	ia(a,n);

	q.push(a[0]);
	p=a[0];

	m[a[0]]++;

	for(i=1;i<n;i++)
	{

		while(v[p][a[i]]!=1 && !q.empty() )
		{
			q.pop();
			if(!q.empty())
			p=q.front();
		}
		cout<<"p"<<p<<" "<<a[i]<<" "<<i<<endl;
		if(v[p][a[i]]!=1)
		break;

		q.push(a[i]);
		m[a[i]]++;
	}

	if(m.size()==n)
	cout<<"Yes";
	else
	cout<<"No";
}


#include <bits/stdc++.h>
#include <thread>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx])return 0;
        if(flag[curr])continue;
        flag[curr]=true;
        if(tree[curr].size()==2) {
            if (path[nxt] == tree[curr][0]) {
                q.push(tree[curr][0]);
                q.push(tree[curr][1]);
            } else if (path[nxt] == tree[curr][1]) {
                q.push(tree[curr][1]);
                q.push(tree[curr][0]);
            }else
            return 0;
        }else if(tree[curr].size()==1)
            q.push(tree[curr][0]);
        nxt+=tree[curr].size();
        idx++;
    }
    return  1;
}
int main() {
    int n,x,y;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
int n,x,y;
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx])return 0;
        idx++;
        if(flag[curr])continue;
        flag[curr]=true;
            while(binary_search(tree[curr].begin(),tree[curr].end(),path[nxt])){
                q.push(path[nxt]);
                nxt++;
            }
    }
    if(idx!=n)
        return 0;
    return  1;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        sort(tree[i+1].begin(),tree[i+1].end());
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
int n,x,y;
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx])return 0;
        if(flag[curr])continue;
        flag[curr]=true;
            while(binary_search(tree[curr].begin(),tree[curr].end(),path[nxt])){
                q.push(path[nxt]);
                nxt++;
            }
        idx++;
    }
    if(idx!=n)
        return 0;
    return  1;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        sort(tree[i+1].begin(),tree[i+1].end());
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
int n,x,y;
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx])return 0;
        if(flag[curr])continue;
        flag[curr]=true;
            while(binary_search(tree[curr].begin(),tree[curr].end(),path[nxt])){
                q.push(path[nxt]);
                nxt++;
            }
        idx++;
    }
    if(idx!=n)
        return 0;
    return  1;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
int n,x,y;
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx++])return 0;
        //cout<<curr<<" "<<q.size()<<endl;
            while(nxt<n&&binary_search(tree[curr].begin(),tree[curr].end(),path[nxt])){

                if(!flag[path[nxt]]) {
                  //  cout<<curr<<" "<<path[nxt]<<endl;
                    flag[path[nxt]] = true;
                    q.push(path[nxt]);
                }nxt++;
            }
    }
    if(idx!=n)
        return 0;
    return  1;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    for(int i=0;i<n;i++){
        sort(tree[i+1].begin(),tree[i+1].end());
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
int n,x,y;
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(flag[curr])continue;
        flag[curr]=true;
            while(binary_search(tree[curr].begin(),tree[curr].end(),path[nxt])){
                q.push(path[nxt]);
                nxt++;
            }
        idx++;
    }
    if(idx!=n)
        return 0;
    return  1;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
int n,x,y;
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx])return 0;
        if(flag[curr])continue;
        flag[curr]=true;
            while(binary_search(tree[curr].begin(),tree[curr].end(),path[nxt])){
                q.push(path[nxt]);
                nxt++;
            }
        idx++;
    }
    for(int i=1;i<=n;i++)
        if(!flag[i])
            return 0;
    return  1;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
int n,x,y;
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0,nxt=1;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx])return 0;
        idx++;
            while(binary_search(tree[curr].begin(),tree[curr].end(),path[nxt])){
                if(flag[path[nxt]])continue;
                flag[curr]=true;
                q.push(path[nxt++]);
            }
    }
    if(idx!=n)
        return 0;
    return  1;
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        sort(tree[i+1].begin(),tree[i+1].end());
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
#include <thread>
using namespace std;
vector<vector<int> > tree((int)1e6);
int path[(int)1e6];
bool bfs(int start){
    queue<int>q;
    q.push(start);
    bool flag[(int)1e6]={0};
    int idx=0;
    while(q.size()){
        int curr=q.front();q.pop();
        if(curr!=path[idx])return 0;
        if(flag[curr])continue;
        flag[curr]=true;
        if(tree[curr].size()==2) {
            if (path[idx + 1] == tree[curr][0]) {
                q.push(tree[curr][0]);
                q.push(tree[curr][1]);
            } else if (path[idx + 1] == tree[curr][1]) {
                q.push(tree[curr][1]);
                q.push(tree[curr][0]);
            }else
            return 0;
        }else if(tree[curr].size()==1)
            q.push(tree[curr][0]);
            idx++;

    }
    return  1;
}
int main() {
    int n,x,y;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        tree[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&path[i]);
    }
    if(path[0]==1&&bfs(path[0])==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=INFll){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}

int solve(){
    int n;
    cin>>n;
    vector<set<int>> gr(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        gr[u].insert(v);
        gr[v].insert(u);
    }
    queue<int> orig,my;
    for(int i=0;i<n;++i){
        int x;cin>>x;
        --x;
        orig.push(x);
    }
    assert(orig.front()!=0);
    if(orig.front()!=0) return cout<<"No\n",0;
    orig.pop();
    my.push(0);
    while(!orig.empty()){
        int cur = my.front();
        if(gr[cur].empty()) my.pop();
        cur = my.front();
        int go = orig.front();
        orig.pop();
        if(gr[cur].count(go)){
            my.push(go);
            gr[cur].erase(go);
            gr[go].erase(cur);
        }else{
            return cout<<"No\n",0;
        }
        if(gr[cur].empty()) my.pop();
    }
    cout<<"Yes\n";
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=INFll){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}

int solve(){
    int n;
    cin>>n;
    vector<set<int>> gr(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        gr[u].insert(v);
        gr[v].insert(u);
    }
    queue<int> orig,my;
    for(int i=0;i<n;++i){
        int x;cin>>x;
        --x;
        orig.push(x);
    }
    if(orig.front()!=0) return cout<<"No\n",0;
    orig.pop();
    my.push(0);
    while(!orig.empty()){
        int cur = my.front();
        if(gr[cur].empty()) my.pop();
        cur = my.front();
        int go = orig.front();
        orig.pop();
        if(gr[cur].count(go)){
            my.push(go);
            gr[cur].erase(go);
            gr[go].erase(cur);
        }else{
            return cout<<"No\n",0;
        }
        if(gr[cur].empty()) my.pop();
    }
    cout<<"Yes\n";
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=INFll){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}

int solve(){
    int n;
    cin>>n;
    vector<set<int>> gr(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        gr[u].insert(v);
        gr[v].insert(u);
    }
    queue<int> orig,my;
    for(int i=0;i<n;++i){
        int x;cin>>x;
        orig.push(x);
    }
	if(orig.front()!=1) return cout<<"No\n",0;
    orig.pop();
    my.push(1);
    while(!orig.empty()){
        int cur = my.front()-1;
        int go = orig.front()-1;
        orig.pop();
        if(gr[cur].count(go)){
            my.push(go+1);
            gr[cur].erase(go);
			gr[go].erase(cur);
        }else{
            return cout<<"No\n",0;
        }
        if(gr[cur].empty()) my.pop();
    }
    cout<<"Yes\n";
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=INFll){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}

int solve(){
    int n;
    cin>>n;
    vector<set<int>> gr(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        gr[u].insert(v);
        gr[v].insert(u);
    }
    queue<int> orig,my;
    for(int i=0;i<n;++i){
        int x;cin>>x;
        --x;
        orig.push(x);
    }
    //assert(orig.front()==0);
    if(orig.front()!=0) return cout<<"No\n",0;
    orig.pop();
    my.push(0);
    while(!orig.empty()){
        int cur = my.front();
        while(gr[cur].empty()){
            my.pop();
            if(my.empty()) return cout<<"No\n",0;
            cur = my.front();
        }
        int go = orig.front();
        if(gr[cur].count(go)){
            my.push(go);
            gr[cur].erase(go);
            gr[go].erase(cur);
            orig.pop();
            if(gr[cur].size() == 0) my.pop();
        }else{
            return cout<<"No\n",0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=INFll){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}

int solve(){
    int n;
    cin>>n;
    vector<set<int>> gr(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        gr[u].insert(v);
        gr[v].insert(u);
    }
    queue<int> orig,my;
    for(int i=0;i<n;++i){
        int x;cin>>x;
        --x;
        orig.push(x);
    }
    assert(orig.front()==0);
    if(orig.front()!=0) return cout<<"No\n",0;
    orig.pop();
    my.push(0);
    while(!orig.empty()){
        int cur = my.front();
        if(gr[cur].empty()) my.pop();
        cur = my.front();
        int go = orig.front();
        orig.pop();
        if(gr[cur].count(go)){
            my.push(go);
            gr[cur].erase(go);
            gr[go].erase(cur);
        }else{
            return cout<<"No\n",0;
        }
        if(gr[cur].empty()) my.pop();
    }
    cout<<"Yes\n";
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=INFll){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}

int solve(){
    int n;
    cin>>n;
    vector<set<int>> gr(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        gr[u].insert(v);
        gr[v].insert(u);
    }
    queue<int> orig,my;
    for(int i=0;i<n;++i){
        int x;cin>>x;
        --x;
        orig.push(x);
    }
    assert(orig.front()==0);
    if(orig.front()!=0) return cout<<"No\n",0;
    orig.pop();
    my.push(0);
    while(!orig.empty()){
        int cur = my.front();
        if(gr[cur].empty()) my.pop();
        cur = my.front();
        int go = orig.front();
        orig.pop();
        if(gr[cur].count(go)!=0){
            my.push(go);
            gr[cur].erase(go);
            gr[go].erase(cur);
        }else{
            return cout<<"No\n",0;
        }
        if(gr[cur].empty()) my.pop();
    }
    cout<<"Yes\n";
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
typedef long double ld;
const ll INFll = 8e18;
const int INFint = 2e9;
const ll MOD = 1e9 + 7;
void needForSpeed(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
bool isPrime(ll a){if(a<2)return 0;for(ll i=2;i<=sqrt(a);i++)if(a%i==0) return 0;return 1;}
ll binpow(ll base, ll pow, ll mod=INFll){
    if(pow==0) return 1;
    else if(pow%2) return base*binpow(base,pow-1,mod)%mod;
    else{
        ll p = binpow(base,pow/2LL,mod);
        return p*p%mod;
    }
}
template<class T>
void PR_VEC(const vector<T> &vec){
    cout<<"size("<<vec.size()<<"):[ '";
    if(vec.size()==0) {
        cout<<"!EMPTY!' ]\n";
        return;
    }
    cout<<vec[0]<<"'";
    for(int i=1;i<vec.size();++i) cout<<" , '"<<vec[i]<<"'";
    cout<<" ]\n";
}

int solve(){
    int n;
    cin>>n;
    vector<set<int>> gr(n);
    for(int i=0;i<n-1;++i){
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        gr[u].insert(v);
        gr[v].insert(u);
    }
    queue<int> orig,my;
    for(int i=0;i<n;++i){
        int x;cin>>x;
        --x;
        orig.push(x);
    }
    assert(orig.front()==0);
    if(orig.front()!=0) return cout<<"No\n",0;
    orig.pop();
    my.push(0);
    while(!orig.empty()){
        int cur = my.front();
        int go = orig.front();
        if(gr[cur].count(go)){
            my.push(go);
            gr[cur].erase(go);
            gr[go].erase(cur);
            orig.pop();
            if(gr[cur].size() == 0) my.pop();
        }else{
            return cout<<"No\n",0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

int main(){
    needForSpeed();
    int tests=1;
    //cin>>tests;
    while (tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef complex<long double> cmplx;
const long double pi = 3.14159265358979323846;
const int inf = (int)2e+9 + 2;
const int mod = 998244353;
const long double eps = 1e-8;
const int N = 100'000;

int n, m, k1, k2;
vector<int> g[1000];
int a[1000];
int b[1000];
int was[1000];
int q[1000];

int ask(int val, char type)
{
  cout << type << ' ' << val + 1 << endl;
  int res;
  cin >> res;
  --res;
  return res;
}

void solve(int test)
{
  cin >> 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);
  }
  cin >> k1;
  for (int i = 0; i < k1; ++i) {
    int x; cin >> x; --x;
    a[x] = test;
  }
  cin >> k2;
  for (int i = 0; i < k2; ++i)  {
    int x; cin >> x; --x;
    b[x] = test;
  }
  int qb = 0, qe = 1;
  q[0] = ask(b[0], 'B');
  was[q[0]] = test;
  for (;;) {
    int v = q[qb++];
    for (auto to : g[v]) {
      if (a[to] == test) {
        qb = to;
        goto out;
      }
      if (was[to] != test) {
        was[to] = test;
        q[qe++] = to;
      }
    }
  }
out:
  if (b[ask(qb, 'A')] == test)
    cout << qb + 1 << endl;
  else
    cout << "C -1" << endl;
  for (int i = 0; i < n; ++i)
    g[i].clear();
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  cin >> test;
  for (int i = 1; i <= test; ++i)
      solve(test);
  return 0;
}