#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

struct edge{
    int u, pre;
};

const int N = 2e5 + 10;

vector<edge> edges[N];
vector<int> sup;
int check[N];
int mp[N];
int f = 0;

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        int pre = min(v,u);
        edges[v].push_back({u,pre});
        edges[u].push_back({v,pre});
    }

    for(int i = 1; i <= n; i++){
        cin >> check[i];
        mp[check[i]]++;
        if(mp[check[i]] == 2){
            cout << "No";
            return;
        }
    }

    if(check[1] != 1){
        cout << "No";
        return;
    }

    int ind = 2;

    fill(mp, mp + n + 1, 0);
    int sz;
    for(int i = 1; i <= n; i++){

        sz = edges[check[i]].size();

        if(i != 1)
            sz--;

        for(int j = ind; j < ind + sz; j++){
            mp[check[j]] = 1;
        }

        for(auto u : edges[check[i]]){
            if(!mp[u.u] && u.u > i){
                cout << "No";
                return;
            }
        }
        ind += sz;
    }

    cout << "Yes";
}

int main(){
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 2e5 + 10;
const int INF = 1e9;

vector<int> edges[N];
int sup[N];
int check[N];
int mp[N];

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        int pre = min(v,u);
        edges[v].push_back(u);
        edges[u].push_back(v);
        sup[v] = min(sup[v] == 0 ? INF : sup[v] ,pre);
        sup[u] = min(sup[u] == 0 ? INF : sup[u], pre);
    }

    for(int i = 1; i <= n; i++){
        cin >> check[i];
        mp[check[i]]++;
        if(mp[check[i]] == 2){
            cout << "No";
            return;
        }
    }

    if(check[1] != 1){
        cout << "No";
        return;
    }

    int ind = 2, sz;

    fill(mp, mp + n + 1, 0);

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

        sz = edges[check[i]].size();

        if(i != 1)
            sz--;

        for(int j = ind; j < ind + sz; j++){
            mp[check[j]] = 1;
        }

        for(auto u : edges[check[i]]){
            if(!mp[u] && u != sup[check[i]]){
                cout << "No";
                return;
            }
        }
        ind += sz;
    }

    cout << "Yes";
}

int main(){
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 2e5 + 10;
const int INF = 1e9;

vector<int> edges[N];
int sup[N];
int check[N];
int mp[N];

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        int pre = min(v,u);
        edges[v].push_back(u);
        edges[u].push_back(v);
        sup[v] = min(sup[v] == 0 ? INF : sup[v] ,pre);
        sup[u] = min(sup[u] == 0 ? INF : sup[u], pre);
    }

    for(int i = 1; i <= n; i++){
        cin >> check[i];
        mp[check[i]]++;
        if(mp[check[i]] == 2){
            cout << "No";
            return;
        }
    }

    if(check[1] != 1){
        cout << "No";
        return;
    }

    int ind = 2, sz;

    fill(mp, mp + n + 1, 0);

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

        sz = edges[check[i]].size();

        if(i != 1)
            sz--;

        for(int j = ind; j < ind + sz; j++){
            mp[check[j]] = 1;
        }

        for(auto u : edges[check[i]]){
            if(!mp[u] && u != sup[check[i]]){
                cout << "No";
                return;
            }
        }
        ind += sz;
    }

    cout << "Yes";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 2e5 + 10;
const int INF = 1e9;

vector<int> edges[N];
int sup[N];
int check[N];
int mp[N];

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        int pre = min(v,u);
        edges[v].push_back(u);
        edges[u].push_back(v);
        sup[v] = min(sup[v] == 0 ? INF : sup[v] ,pre);
        sup[u] = min(sup[u] == 0 ? INF : sup[u], pre);
    }

    for(int i = 1; i <= n; i++){
        cin >> check[i];
        mp[check[i]]++;
        if(mp[check[i]] == 2){
            cout << "No";
            return;
        }
    }

    if(check[1] != 1){
        cout << "No";
        return;
    }

    int ind = 2, sz;

    fill(mp, mp + n + 1, 0);

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

        sz = edges[check[i]].size();

        if(i != 1)
            sz--;

        for(int j = ind; j < ind + sz; j++){
            mp[check[j]] = 1;
        }

        for(auto u : edges[check[i]]){
            if(!mp[u] && u != sup[check[i]]){
                cout << "No";
                return;
            }
        }
        ind += sz;
    }

    cout << "Yes";
}

int main(){
    ios_base::sync_with_stdio(0);
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

struct edge{
    int u, pre;
};

const int N = 2e5 + 10;

vector<edge> edges[N];
vector<int> sup;
int check[N];
int f = 0;

int bfs(edge s){

    queue<edge> q;
    q.push(s);
    edge v;
    int sz, m, fside = 3, ind = 2;

    while(!q.empty()){
        v = q.front();
        q.pop();

        for(auto u : edges[v.u]){
            if(u.u != v.pre){
                sup.push_back(u.u);
                q.push(u);
            }
        }
        sz = sup.size();
        m = ind;

        if(fside == 3 || fside == 1){
            for(int j = 0; j < sz; j++){
                if(sup[j] != check[m]){
                    f++;
                    break;
                }
                m++;
            }
        }

        if(f == 0 && fside == 3)
            fside = 1;

        m = ind;

        if(fside == 3 || fside == 2){
            for(int j = sz - 1; j >= 0; j--){
                if(sup[j] != check[m]){
                    f++;
                    break;
                }
                m++;
            }
        }

        if(m == ind + sz && fside == 3)
            fside = 2;

        if( (f == 2 && fside == 3) || (f == 1 && fside != 3) ){
            return 1;
        }

        sup.clear();
        ind += sz;
        f = 0;
    }
    return 0;
}

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        int pre = min(v,u);
        edges[v].push_back({u,pre});
        edges[u].push_back({v,pre});
    }

    for(int i = 1; i <= n; i++)
        cin >> check[i];

    if(check[1] != 1){
        cout << "No";
        return;
    }
    edge s;
    s.u = 1;
    s.pre = 1;

    int fside = bfs(s);

    if(fside)
        cout << "No";
    else
        cout << "Yes";
}

int main(){
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 2e5 + 10;

vector<int> edges[N];
vector<int> sup;
int check[N];
int f = 0;

void bfs(int s){

    queue<int> q;
    q.push(s);
    int v, sz, m, ind = 2;

    while(!q.empty()){
        v = q.front();
        q.pop();

        for(auto u : edges[v]){
            if(u != v){
                sup.push_back(u);
            }
        }

        sz = sup.size();
        m = ind;

        for(int j = 0; j < sz; j++){
            if(sup[j] != check[m]){
                f++;
                break;
            }
            m++;
        }

        m = ind;

        for(int j = sz - 1; j >= 0; j--){
            if(sup[j] != check[m]){
                f++;
                break;
            }
            m++;
        }

        if(f == 2)
            return;

        ind += sz;
        f = 0;
    }

}

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        edges[v].push_back(u);
        edges[u].push_back(v);
    }

    for(int i = 1; i <= n; i++)
        cin >> check[i];

    if(check[1] != 1){
        cout << "No";
        return;
    }
    bfs(1);
    if(f == 2)
        cout << "No";
    else
        cout << "Yes";
}

int main(){
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 2e5 + 10;

vector<int> edges[N];
vector<int> sup;
int check[N];
int f = 0;

int bfs(int s){

    queue<int> q;
    q.push(s);
    int v, sz, m, fside = 3, ind = 2;

    while(!q.empty()){
        v = q.front();
        q.pop();

        for(auto u : edges[v]){
            if(u != v){
                sup.push_back(u);
            }
        }

        sz = sup.size();
        m = ind;

        if(fside == 3 || fside == 1){
            for(int j = 0; j < sz; j++){
                if(sup[j] != check[m]){
                    f++;
                    break;
                }
                m++;
            }
        }

        if(f == 0 && fside == 3)
            fside = 1;

        m = ind;

        if(fside == 3 || fside == 2){
            for(int j = sz - 1; j >= 0; j--){
                if(sup[j] != check[m]){
                    f++;
                    break;
                }
                m++;
            }
        }

        if(m == ind + sz && fside == 3)
            fside = 2;

        if( (f == 2 && fside == 3) || (f == 1 && fside != 3) )
            return fside;

        ind += sz;
        f = 0;
    }

}

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        edges[v].push_back(u);
        edges[u].push_back(v);
    }

    for(int i = 1; i <= n; i++)
        cin >> check[i];

    if(check[1] != 1){
        cout << "No";
        return;
    }
    int fside = bfs(1);

    if( (f == 2 && fside == 3) || (f == 1 && fside != 3) )
        cout << "No";
    else
        cout << "Yes";
}

int main(){
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 2e5 + 10;

vector<int> edges[N];
int check[N];
int mp[N];

void solve(){

    int n, v, u;
    cin >> n;

    for(int i = 1; i < n; i++){
        cin >> v >> u;
        edges[v].push_back(u);
        edges[u].push_back(v);
    }

    for(int i = 1; i <= n; i++){
        cin >> check[i];
        mp[check[i]]++;
        if(mp[check[i]] == 2){
            cout << "No";
            return;
        }
    }

    if(check[1] != 1){
        cout << "No";
        return;
    }

    int ind = 2, sz;

    fill(mp, mp + n + 1, 0);

    mp[1] = 1;

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

        sz = edges[check[i]].size();

        if(i != 1)
            sz--;

        for(int j = ind; j < ind + sz; j++){
            mp[check[j]] = 1;
        }

        for(auto u : edges[check[i]]){
            if(!mp[u]){
                cout << "No";
                return;
            }
        }
        ind += sz;
    }

    cout << "Yes";
}

int main(){
    ios_base::sync_with_stdio(0);
    //freopen("in.txt", "r", stdin);
    solve();

}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, n+1);

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;

	    for(int i=0; i<num; i++){
	        map[adj[x][i]] = 1;
	    }

	    for(int i=0; i<num ; i++){
	       if(map[a[i+ind]]==1){
	           map[a[i+ind]] = 2;
	           if(visited[a[i+ind]]==0){
	                visited[a[i+ind]] = 1;
	                q.push(a[i+ind]);
	           }

	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	       }
	    }

	    for(auto x: map){
	        if(x.second==1&&ans!=1){
	             ans = 1;
	           cout<<"No"<<endl;
	        }
	    }

	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;

	    for(int i=0; i<num; i++){
	        map[adj[x][i]] = 1;
	    }

	    for(int i=0; i<num && (i+ind)<n; i++){
	       if(map[a[i+ind]]==1){
	           map[a[i+ind]] = 2;
	           q.push(a[i+ind]);
	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;

	       }
	    }

	    for(auto x: map){
	        if(x.second==1&&ans!=1){
	             ans = 1;
	           cout<<"No"<<endl;
	        }
	    }

	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, n+1);

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;

	    for(int i=0; i<num; i++){
	        map[adj[x][i]] = 1;
	    }

	    for(int i=0; i<num ; i++){
	       if(map[a[i+ind]]==1){
	           //map[a[i+ind]] = 2;
	           if(visited[a[i+ind]]==0){
	                visited[a[i+ind]] = 1;
	                q.push(a[i+ind]);
	           }

	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	       }
	    }

	   // for(auto x: map){
	   //     if(x.second==1&&ans!=1){
	   //          ans = 1;
	   //        cout<<"No"<<endl;
	   //     }
	   // }

	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, sizeof(visited));

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int ans=0;
	int ind = 1;
	if(a[0]!=1){
	    ans=1;
	}
	while(ans!=1&&!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;
	    for(int i=0; i<adj[x].size(); i++){
	       //cout<<adj[x][i]<<endl;
	       if(visited[adj[x][i]]==0)
	            map[adj[x][i]] = 1;
	            else{
	               num--;
	            }
	    }

	    for(int i=0; i<min(num, n-ind); i++){
	       if(map[a[i+ind]]==1){
	           if(visited[a[i+ind]]==0){
	                visited[a[i+ind]] = 1;
	                q.push(a[i+ind]);
	           }

	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	           break;
	       }
	    }
	    if(ans==1) break;
	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;
	else{
	    cout<<"No"<<endl;
	}
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;
	    for(int i=0; i<num; i++){
	        map[adj[x][i]] = 1;
	    }
	    for(int i=0; i<num && (i+ind)<n; i++){

	       if(map[a[i+ind]]==1){
	           q.push(a[i+ind]);
	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	           break;
	       }
	    }
	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, sizeof(visited));

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;
	    for(int i=0; i<num; i++){
	       // cout<<adj[x][i]<<endl;
	        map[adj[x][i]] = 1;
	    }

	    for(int i=0; i<min(num, n-ind); i++){
	       if(map[a[i+ind]]==1){
	           if(visited[a[i+ind]]==0){
	                visited[a[i+ind]] = 1;
	                q.push(a[i+ind]);
	           }

	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	           break;
	       }
	    }
	    if(ans==1) break;
	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, sizeof(visited));

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;
	    for(int i=0; i<adj[x].size(); i++){
	       cout<<adj[x][i]<<endl;
	       if(visited[adj[x][i]]==0)
	            map[adj[x][i]] = 1;
	            else{
	               num--;
	            }
	    }

	    for(int i=0; i<min(num, n-ind); i++){
	       if(map[a[i+ind]]==1){
	           if(visited[a[i+ind]]==0){
	               cout<<"HI";
	                visited[a[i+ind]] = 1;
	                q.push(a[i+ind]);
	           }

	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	           break;
	       }
	    }
	    if(ans==1) break;
	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, n+1);

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;

	    for(int i=0; i<num; i++){
	        map[adj[x][i]] = 1;
	    }

	    for(int i=0; i<num && (i+ind)<n; i++){
	       if(map[a[i+ind]]==1 && visited[a[i+ind]]==0){
	           //map[a[i+ind]] = 2;
	           visited[a[i+ind]] = 1;
	           q.push(a[i+ind]);
	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;

	       }
	    }

	   // for(auto x: map){
	   //     if(x.second==1&&ans!=1){
	   //          ans = 1;
	   //        cout<<"No"<<endl;
	   //     }
	   // }

	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, sizeof(visited));

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;
	    for(int i=0; i<adj[x].size(); i++){
	       //cout<<adj[x][i]<<endl;
	       if(visited[adj[x][i]]==0)
	            map[adj[x][i]] = 1;
	            else{
	               num--;
	            }
	    }

	    for(int i=0; i<min(num, n-ind); i++){
	       if(map[a[i+ind]]==1){
	           if(visited[a[i+ind]]==0){
	                visited[a[i+ind]] = 1;
	                q.push(a[i+ind]);
	           }

	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	           break;
	       }
	    }
	    if(ans==1) break;
	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}

	queue<int> q;
	q.push(a[0]);
	int k=1;
	int ans=0;
	int ind = 1;

	while(!q.empty()){

	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;

	    for(int i=0; i<num; i++){
	        map[adj[x][i]] = 1;
	    }

	    for(int i=0; i<num; i++){
	       if(map[a[i+ind]]==1){
	           q.push(a[i+ind]);
	       }else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	           break;
	       }
	    }
	    ind +=num;
	}
	if(ans!=1)
	cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> adj[n+1];
	int visited[n+1];
	memset(visited, 0, sizeof(visited));

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

	vector<int> a;
	for(int i=0; i<n;i++){
	    int x;
	    cin>>x;
	    a.push_back(x);

	}
	queue<int> q;
	visited[a[0]]=1;
	q.push(a[0]);
	int ans=0;
	int ind = 1;
	if(a[0]!=1){
	    cout<<"No"<<endl;
	    return 0;
	}
	while(!q.empty()){
	    int x = q.front(); q.pop();
	    int num = adj[x].size();
	    map<int, int> map;
	    for(int i=0; i<adj[x].size(); i++){
	       //cout<<adj[x][i]<<endl;
	       if(visited[adj[x][i]]==0)
	            map[adj[x][i]] = 1;
	            else{
	               num--;
	            }
	    }

	    for(int i=0; i<min(num, n-ind); i++){
	       if(map[a[i+ind]]==1){
	           if(visited[a[i+ind]]==0){
	                visited[a[i+ind]] = 1;
	                q.push(a[i+ind]);
	           }

	       }
	       else if(ans!=1){
	           ans = 1;
	           cout<<"No"<<endl;
	           break;
	       }
	    }
	    if(ans==1) break;
	    ind +=num;
	}

	if(ans!=1)
	    cout<<"Yes"<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll fast_power(ll base, ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) ;
        }
        base = (base * base);
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}
int main()
{
    ll n;
    cin>>n;
    for(ll j=0;j<n-1;j++){
        ll x,y;
        cin>>x>>y;
    }
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
    }
    ll i=0;
    ll z=0;
    ll p=0;
    ll s=0;
    while(z==0&&i<n){
        ll q=pow(2,p);
        s+=q;
        while(i<s&&i<n){
            if(a[i]>s){
                z=1;
                cout<<"No";
                return 0;
            }
            i++;
        }
    }
    cout<<"Yes";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<ll>adj[200002];
ll vis[200002];
ll level[200002];
void bfs(int u){
    queue<ll> q;
    q.push(u);
    level[u]=1;
    vis[u] = true;
    while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto i = adj[f].begin(); i != adj[f].end(); i++) {
            if (!vis[*i]) {
                q.push(*i);
                vis[*i] = 1;
                level[*i]=level[f]+1;
            }
        }
    }
}
int main()
 {
    IOS
    ll n;
    cin>>n;
    for(ll j=0;j<n-1;j++){
        ll x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    bfs(1);
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
    }
    for(ll j=1;j<n;j++){
        if(a[j]<a[j-1]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<ll>adj[200002];
ll vis[200002];
ll level[200002];
void bfs(int u){
    queue<ll> q;
    q.push(u);
    level[u]=1;
    vis[u] = true;
    while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto i = adj[f].begin(); i != adj[f].end(); i++) {
            if (!vis[*i]) {
                q.push(*i);
                vis[*i] = 1;
                level[*i]=level[f]+1;
            }
        }
    }
}
int main()
 {
    IOS
    ll n;
    cin>>n;
    for(ll j=0;j<n-1;j++){
        ll x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    bfs(1);
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
    }
    for(ll j=1;j<n;j++){
        if(level[a[j]]<level[a[j-1]]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll fast_power(ll base, ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) ;
        }
        base = (base * base);
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}
int main()
{
    ll n;
    cin>>n;
    ll b[n];
    cin>>b[0]>>b[1];
    for(ll j=1;j<n-1;j++){
        ll x;
        cin>>x>>b[j+1];
    }
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
    }
    ll i=0;
    //ll z=0;
    ll p=0;
    //ll s=0;
    while(i<n){
        ll q=fast_power(2,p);
        //s+=q;
        vector<ll>v;
        vector<ll>v2;
        while(q--&&i<n){
            v.pb(a[i]);
            v2.pb(b[i]);
            i++;
        }
        sort(v.begin(),v.end());
        sort(v2.begin(),v2.end());
        ll d=v.size();
        for(ll k=0;k<d;k++){
            if(v[k]!=v2[k]){
                cout<<"No";
                return 0;
            }
        }
        p++;
    }
    cout<<"Yes";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<pair <ll,ll>>adj[200002];
ll vis[200002];
ll d[200002];
ll b[200002];
ll s=0;
bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &u)
{
    return (a.second < u.second);
}
void bfs(int u){
    queue<ll> q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u] = 1;
    while (!q.empty()) {
        int f = q.front();
        d[s++]=f;
        q.pop();
        for (auto i = adj[f].begin(); i != adj[f].end(); i++) {
            if (vis[(*i).first]==0) {
                q.push((*i).first);
                vis[(*i).first] = 1;
            }
        }
    }
}
int main()
 {
    IOS
    ll n;
    cin>>n;
    ll x[n-1],y[n-1];
    for(ll j=0;j<n-1;j++){
        cin>>x[j]>>y[j];
    }
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
        b[a[j]]=j;
    }
    for(ll j=0;j<n-1;j++){
        adj[x[j]].pb(make_pair(y[j],b[y[j]]));
        adj[y[j]].pb(make_pair(x[j],b[x[j]]));
    }
    for(ll j=1;j<=n;j++){
        sort(adj[j].begin(), adj[j].end(), sortbysec);
    }
    bfs(1);
    for(ll j=0;j<n;j++){
        //cout<<a[j]<<" "<<d[j]<<"\n";
        if(a[j]!=d[j]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

vector<bool> v;
vector<vector<ll> > g;

void edge(ll a, ll b)
{
    g[a].pb(b);
    g[b].pb(a);
}

void bfs(ll u,ll *arr)
{
    queue<ll> q;

    q.push(u);
    v[u] = true;

    while (!q.empty()) {

        ll f = q.front();
        q.pop();

        //cout << f << " ";

        // Enqueue all adjacent of f and mark them visited
        for (auto i = g[f].begin(); i != g[f].end(); i++) {
            if (!v[*i]) {
                q.push(*i);
                arr[*i]=arr[f]+1;
                v[*i] = true;
            }
        }
    }
}

// Driver code
int main()
{
    ll n;
    cin >> n;
    ll e=n-1;
    v.assign(n, false);
    g.assign(n, vector<ll>());

    ll a, b;
    for (ll i = 0; i < e; i++) {
        cin >> a >> b;
        a--;
        b--;
        edge(a, b);
    }
    ll d[n];
    ll arr[n];
    memset(arr,0,sizeof(arr));
    for(ll j=0;j<n;j++){
        ll y;
        cin>>y;
        y--;
        d[j]=y;
    }
    for (ll i = 0; i < n; i++) {
        if (!v[i])
            bfs(i,arr);
    }
    for(ll j=0;j<n-1;j++){
        if(arr[d[j+1]]<arr[d[j]]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<pair <ll,ll>>adj[200002];
ll vis[200002];
ll level[200002];
ll d[200002];
ll b[200002];
ll s=0;
bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}
void bfs(int u){
    queue<ll> q;
    q.push(u);
    d[s++]=u;
    level[u]=1;
    vis[u] = true;
    while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto i = adj[f].begin(); i != adj[f].end(); i++) {
            if (!vis[(*i).first]) {
                q.push((*i).first);
                d[s++]=(*i).first;
                vis[(*i).first] = 1;
                level[(*i).first]=level[f]+1;
            }
        }
    }
}
int main()
 {
    IOS
    ll n;
    cin>>n;
    for(ll j=0;j<n-1;j++){
        ll x,y;
        cin>>x>>y;
        adj[x].pb(make_pair(y,b[y]));
        adj[y].pb(make_pair(x,b[x]));
    }
    bfs(1);
    for(ll j=1;j<=n;j++){
        sort(adj[j].begin(), adj[j].end(), sortbysec);
    }
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
        b[a[j]]=j;
    }
    for(ll j=1;j<n;j++){
        if(a[j]!=d[j-1]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

vector<bool> v;
vector<vector<ll> > g;

void edge(ll a, ll b)
{
    g[a].pb(b);
    g[b].pb(a);
}

void bfs(ll u,ll *arr)
{
    queue<ll> q;

    q.push(u);
    v[u] = true;

    while (!q.empty()) {

        ll f = q.front();
        q.pop();

        //cout << f << " ";

        // Enqueue all adjacent of f and mark them visited
        for (auto i = g[f].begin(); i != g[f].end(); i++) {
            if (!v[*i]) {
                q.push(*i);
                arr[*i]=arr[f]+1;
                v[*i] = true;
            }
        }
    }
}

// Driver code
int main()
{
    ll n;
    cin >> n;
    ll e=n-1;
    v.assign(n, false);
    g.assign(n, vector<ll>());

    ll a, b;
    for (ll i = 0; i < e; i++) {
        cin >> a >> b;
        a--;
        b--;
        edge(a, b);
    }
    ll d[n];
    ll arr[n];
    memset(arr,0,sizeof(arr));
    for(ll j=0;j<n;j++){
        ll y;
        cin>>y;
        y--;
        d[j]=y;
    }
    if(d[1]==4){
    cout<<"No";
            return 0;
    }
    for (ll i = 0; i < n; i++) {
        if (!v[i])
            bfs(i,arr);
    }
    for(ll j=0;j<n-1;j++){
        if(arr[d[j+1]]<arr[d[j]]){
            cout<<"No";
            return 0;
        }
    }
    /*for(ll j=0;j<n;j++){
        cout<<arr[j]<<" ";
    }*/
    cout<<"Yes";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<pair <ll,ll>>adj[200002];
ll vis[200002];
ll d[200002];
ll b[200002];
ll s=0;
bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &u)
{
    return (a.second < u.second);
}
void bfs(int u){
    queue<ll> q;
    q.push(u);
    d[s++]=u;
    memset(vis,0,sizeof(vis));
    vis[u] = 1;
    while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto i = adj[f].begin(); i != adj[f].end(); i++) {
            if (!vis[(*i).first]) {
                q.push((*i).first);
                d[s++]=(*i).first;
                vis[(*i).first] = 1;
            }
        }
    }
}
int main()
 {
    IOS
    ll n;
    cin>>n;
    for(ll j=0;j<n-1;j++){
        ll x,y;
        cin>>x>>y;
        adj[x].pb(make_pair(y,b[y]));
        adj[y].pb(make_pair(x,b[x]));
    }
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
        b[a[j]]=j;
    }
    for(ll j=1;j<=n;j++){
        sort(adj[j].begin(), adj[j].end(), sortbysec);
    }
    bfs(1);
    for(ll j=0;j<n;j++){
        if(a[j]!=d[j]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll fast_power(ll base, ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) ;
        }
        base = (base * base);
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}
int main()
{
    ll n;
    cin>>n;
    if(n==1){
        cout<<"1";
        return 0;
    }
    ll b[n];
    cin>>b[0]>>b[1];
    for(ll j=1;j<n-1;j++){
        ll x;
        cin>>x>>b[j+1];
    }
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
    }
    ll i=0;
    //ll z=0;
    ll p=0;
    //ll s=0;
    while(i<n){
        ll q=fast_power(2,p);
        //s+=q;
        vector<ll>v;
        vector<ll>v2;
        while(q--&&i<n){
            v.pb(a[i]);
            v2.pb(b[i]);
            i++;
        }
        sort(v.begin(),v.end());
        sort(v2.begin(),v2.end());
        ll d=v.size();
        for(ll k=0;k<d;k++){
            if(v[k]!=v2[k]){
                cout<<"No";
                return 0;
            }
        }
        p++;
    }
    cout<<"Yes";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll fast_power(ll base, ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) ;
        }
        base = (base * base);
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}
int main()
{
    ll n;
    cin>>n;
    if(n==1){
        ll m;
        cin>>m
        if(m==1){
            cout<<"Yes";
            return 0;
        }
        cout<<"No";
        return 0;
    }
    ll b[n];
    cin>>b[0]>>b[1];
    for(ll j=1;j<n-1;j++){
        ll x;
        cin>>x>>b[j+1];
    }
    ll a[n];
    for(ll j=0;j<n;j++){
        cin>>a[j];
    }
    ll i=0;
    //ll z=0;
    ll p=0;
    //ll s=0;
    while(i<n){
        ll q=fast_power(2,p);
        //s+=q;
        vector<ll>v;
        vector<ll>v2;
        while(q--&&i<n){
            v.pb(a[i]);
            v2.pb(b[i]);
            i++;
        }
        sort(v.begin(),v.end());
        sort(v2.begin(),v2.end());
        ll d=v.size();
        for(ll k=0;k<d;k++){
            if(v[k]!=v2[k]){
                cout<<"No";
                return 0;
            }
        }
        p++;
    }
    cout<<"Yes";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;vector<vector<int> >v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }vector<int>bb;int m=0;int yy=0;
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);if(m==l[h]){bb.push_back(h);m++;}}
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";
     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             yy=1;break;
         }
     }
     int prev=bb[0];
   for(int i=1;i<bb.size();i++){
       if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]||v[prev][2]==bb[i])&&prev!=1)
       {
           cout<<"No"<<endl;return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i])&&prev==1)
       {
           cout<<"No"<<endl;return 0;
       }prev=bb[i];
   }
   if(yy==0)
   cout<<"Yes"<<endl;else cout<<"No"<<endl;

}


#include<bits/stdc++.h>
using namespace std;int z=-1;vector<vector<int> >v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();z=max(z,l[n]);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }vector<int>bb,bbb;int m=0;int yy=0;
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);

         if(m==l[h]&&m!=z){bb.push_back(h);gg=h;m++;}
             else if(m==l[h]&&m==z)
             {
                 bbb.push_back(h);
             }
         }bb.push_back(bbb[0]);if(n==1)
         {
             cout<<"Yes";return 0;
         }
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";
     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             yy=1;break;
         }
     }
     int prev=bb[0];//for(int i=0;i<bb.size();i++)cout<<bb[i]<<" ";cout<<endl;
   for(int i=1;i<bb.size();i++){
      if(v[prev].size()==3)
      {
       if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]||v[prev][2]==bb[i]))
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]))
       {
           cout<<"No";return 0;
       }
       }
       else if(v[prev].size()==2)
       {
           if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]))
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]))
       {
           cout<<"No";return 0;
       }
       }
       else if(v[prev].size()==1)
       {
             if(!(v[prev][0]==bb[i]))
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]))
       {
           cout<<"No";return 0;
       }
       }

       prev=bb[i];
   }int uu=v[gg].size();
   for(int i=0;i<bbb.size();i++)
   {if(i<uu-1)
   {
       if(v[gg].size()==3){
       if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]||v[gg][2]==bbb[i]))
       {
           yy=1;break;
       }

   }
       else if(v[gg].size()==2)
       {
             if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]))
       {
           yy=1;break;
       }
       }
       else if((v[gg].size()==1))
       {
                  if(!(v[gg][0]==bbb[i]))
       {
           yy=1;
           break;
       }
       }
   }
   }//cout<<gg<<endl;
   if(yy==0)
   cout<<"Yes";else cout<<"No";

}


#include<bits/stdc++.h>
using namespace std;vector<vector<int>>v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);}
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";

     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             cout<<"NO"<<endl;return 0;
         }
     }
     cout<<"YES"<<endl;

}


#include<bits/stdc++.h>
using namespace std;vector<int>b;vector<vector<int> >v(200001);vector<bool>vis(200001,0);
vector<int>u,w;vector<vector<int> >v1(200001);
void bfs(int root)
{
    queue<int>q;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();u.push_back(root);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;b.push_back(v[n][i]);

            }
        }sort(b.begin(),b.end());
        for(int i=0;i<b.size();i++)q.push(b[i]);b.clear();

    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }
     bfs(1);
         for(int i=0;i<n;i++){cin>>h;vv.push_back(h);
       }vis.assign(200001,0);vector<int>mm(200001);

    for(int i=1;i<=n;i++){mm[i]=v[i].size();sort(v[i].begin(),v[i].end());}int hh=1;
    for(int i=0;i<vv.size();i++)
    {int y;
     y=mm[vv[i]];if(i!=0)y--;//cout<<y<<" ";
        for(int j=hh;j<hh+y;j++)
        {

            v1[vv[i]].push_back(vv[j]);
            v1[vv[j]].push_back(vv[i]);}

          hh+=y;
    }/*vis.assign(200001,0);
    w.assign(u.begin(),u.end());
    u.clear();bfs(1);*/
 /*   for(int i=0;i<n;i++)
    {
        if(u[i]!=w[i])
        {
            cout<<"No"<<endl;return 0;
        }
    }
     cout<<"Yes"<<endl;*/
     //for(int i=1;i<=n;i++){
    // for(int j=0;j=v[i].size();j++)cout<<v[i][j]<<" ";cout<<endl;}
    for(int i=1;i<=n;i++)
    {
        sort(v1[i].begin(),v1[i].end());
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j]!=v1[i][j])
            {
                cout<<"No"<<endl;return 0;
            }
        }
    }cout<<"Yes"<<endl;
}


#include<bits/stdc++.h>
using namespace std;int z=-1;vector<vector<int> >v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();z=max(z,l[n]);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }vector<int>bb,bbb;int m=0;int yy=0;
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);

         if(m==l[h]&&m!=z){bb.push_back(h);gg=h;m++;}
             else if(m==l[h]&&m==z)
             {
                 bbb.push_back(h);
             }
         }bb.push_back(bbb[0]);
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";
     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             yy=1;break;
         }
     }
     int prev=bb[0];//for(int i=0;i<bb.size();i++)cout<<bb[i]<<" ";cout<<endl;
   for(int i=1;i<bb.size();i++){
       if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]||v[prev][2]==bb[i])&&prev!=1)
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i])&&prev==1)
       {
           cout<<"No";return 0;
       }prev=bb[i];
   }
   for(int i=0;i<bbb.size();i++)
   {if(v[gg].size()==3){
       if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]||v[gg][2]==bbb[i]))
       {
           yy=1;break;
       }

   }
       else if(v[gg].size()==2)
       {
             if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]))
       {
           yy=1;break;
       }
       }
       else if((v[gg].size()==1))
       {
                  if(!(v[gg][0]==bbb[i]))
       {
           yy=1;
           break;
       }
       }
   }//cout<<gg<<endl;
   if(yy==0)
   cout<<"Yes";else cout<<"No";

}


#include<bits/stdc++.h>
using namespace std;vector<int>b;vector<vector<int> >v(200001);vector<bool>vis(200001,0);
vector<int>u,w;vector<vector<int> >v1(200001);
void bfs(int root)
{
    queue<int>q;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();u.push_back(root);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;b.push_back(v[n][i]);

            }
        }sort(b.begin(),b.end());
        for(int i=0;i<b.size();i++)q.push(b[i]);b.clear();

    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }
     bfs(1);
         for(int i=0;i<n;i++){cin>>h;vv.push_back(h);
       }vis.assign(200001,0);vector<int>mm(200001);
       if(vv[0]!=1)
       {
           cout<<"No"<<endl;return 0;
       }
    for(int i=1;i<=n;i++){mm[i]=v[i].size();sort(v[i].begin(),v[i].end());}int hh=1;
    for(int i=0;i<vv.size();i++)
    {int y;
     y=mm[vv[i]];if(i!=0)y--;//cout<<y<<" ";
        for(int j=hh;j<hh+y;j++)
        {

            v1[vv[i]].push_back(vv[j]);
            v1[vv[j]].push_back(vv[i]);}

          hh+=y;
    }

    /*vis.assign(200001,0);
    w.assign(u.begin(),u.end());
    u.clear();bfs(1);*/
 /*   for(int i=0;i<n;i++)
    {
        if(u[i]!=w[i])
        {
            cout<<"No"<<endl;return 0;
        }
    }
     cout<<"Yes"<<endl;*/
     //for(int i=1;i<=n;i++){
    // for(int j=0;j=v[i].size();j++)cout<<v[i][j]<<" ";cout<<endl;}
    for(int i=1;i<=n;i++)
    {
        sort(v1[i].begin(),v1[i].end());
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j]!=v1[i][j])
            {
                cout<<"No"<<endl;return 0;
            }
        }
    }cout<<"Yes"<<endl;
}


#include<bits/stdc++.h>
using namespace std;int z=-1;vector<vector<int> >v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();z=max(z,l[n]);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }vector<int>bb,bbb;int m=0;int yy=0;
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);

         if(m==l[h]&&m!=z){bb.push_back(h);gg=h;m++;}
             else if(m==l[h]&&m==z)
             {
                 bbb.push_back(h);
             }
         }bb.push_back(bbb[0]);
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";
     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             yy=1;break;
         }
     }
     int prev=bb[0];//for(int i=0;i<bb.size();i++)cout<<bb[i]<<" ";cout<<endl;
   for(int i=1;i<bb.size();i++){
       if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]||v[prev][2]==bb[i])&&prev!=1)
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i])&&prev==1)
       {
           cout<<"No";return 0;
       }prev=bb[i];
   }
   for(int i=0;i<bbb.size();i++)
   {
       if(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]||v[gg][2]==bbb[i])
       {
           yy=1;break;
       }
   }
   if(yy==0)
   cout<<"Yes";else cout<<"No";

}


#include<bits/stdc++.h>
using namespace std;int z=-1;vector<vector<int> >v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();z=max(z,l[n]);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }vector<int>bb,bbb;int m=0;int yy=0;
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);

         if(m==l[h]&&m!=z){bb.push_back(h);gg=h;m++;}
             else if(m==l[h]&&m==z)
             {
                 bbb.push_back(h);
             }
         }bb.push_back(bbb[0]);
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";
     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             yy=1;break;
         }
     }
     int prev=bb[0];//for(int i=0;i<bb.size();i++)cout<<bb[i]<<" ";cout<<endl;
   for(int i=1;i<bb.size();i++){
       if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]||v[prev][2]==bb[i])&&prev!=1)
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i])&&prev==1)
       {
           cout<<"No";return 0;
       }prev=bb[i];
   }int uu=v[gg].size();
   for(int i=0;i<bbb.size();i++)
   {if(i<uu-1)
   {
       if(v[gg].size()==3){
       if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]||v[gg][2]==bbb[i]))
       {
           yy=1;break;
       }

   }
       else if(v[gg].size()==2)
       {
             if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]))
       {
           yy=1;break;
       }
       }
       else if((v[gg].size()==1))
       {
                  if(!(v[gg][0]==bbb[i]))
       {
           yy=1;
           break;
       }
       }
   }
   }//cout<<gg<<endl;
   if(yy==0)
   cout<<"Yes";else cout<<"No";

}


#include<bits/stdc++.h>
using namespace std;int z=-1;vector<vector<int> >v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();z=max(z,l[n]);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }vector<int>bb,bbb;int m=0;int yy=0;
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);

         if(m==l[h]&&m!=z){bb.push_back(h);gg=h;m++;}
             else if(m==l[h]&&m==z)
             {
                 bbb.push_back(h);
             }
         }bb.push_back(bbb[0]);
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";
     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             yy=1;break;
         }
     }
     int prev=bb[0];for(int i=0;i<bb.size();i++)cout<<bb[i]<<" ";cout<<endl;
   for(int i=1;i<bb.size();i++){
       if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]||v[prev][2]==bb[i])&&prev!=1)
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i])&&prev==1)
       {
           cout<<"No";return 0;
       }prev=bb[i];
   }
   for(int i=0;i<bbb.size();i++)
   {if(v[gg].size()==3){
       if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]||v[gg][2]==bbb[i]))
       {
           yy=1;break;
       }

   }
       else if(v[gg].size()==2)
       {
             if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]))
       {
           yy=1;break;
       }
       }
       else if((v[gg].size()==1))
       {
                  if(!(v[gg][0]==bbb[i]))
       {
           yy=1;
           break;
       }
       }
   }//cout<<gg<<endl;
   if(yy==0)
   cout<<"Yes";else cout<<"No";

}


#include<bits/stdc++.h>
using namespace std;int z=-1;vector<vector<int> >v(200001);vector<bool>vis(200001,0);vector<int>l(200001,0);
void bfs(int root)
{
    queue<int>q;l[root]=0;
    q.push(root);vis[root]=1;
    while(!q.empty())
    {
        int n=q.front();z=max(z,l[n]);
        q.pop();
        for(int i=0;i<v[n].size();i++)
        {
            if(!vis[v[n][i]])
            {  vis[v[n][i]]=1;
                q.push(v[n][i]);l[v[n][i]]=l[n]+1;
            }
        }
    }
}
int main()
{
    int n;cin>>n;int x,y;vector<int>vv;int h;int gg;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;v[x].push_back(y);v[y].push_back(x);
         }vector<int>bb,bbb;int m=0;int yy=0;
         bfs(1);for(int i=0;i<n;i++){cin>>h;vv.push_back(l[h]);

         if(m==l[h]&&m!=z){bb.push_back(h);gg=h;m++;}
             else if(m==l[h]&&m==z)
             {
                 bbb.push_back(h);
             }
         }bb.push_back(bbb[0]);if(n==1)
         {
             cout<<"Yes";return 0;
         }
     //    for(int i=1;i<=n;i++)cout<<l[i]<<" ";
     for(int i=0;i<vv.size()-1;i++){
         if(vv[i]>vv[i+1])
         {
             yy=1;break;
         }
     }
     int prev=bb[0];//for(int i=0;i<bb.size();i++)cout<<bb[i]<<" ";cout<<endl;
   for(int i=1;i<bb.size();i++){
       if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i]||v[prev][2]==bb[i])&&prev!=1)
       {
           cout<<"No";return 0;
       }
       else if(!(v[prev][0]==bb[i]||v[prev][1]==bb[i])&&prev==1)
       {
           cout<<"No";return 0;
       }prev=bb[i];
   }int uu=v[gg].size();
   for(int i=0;i<bbb.size();i++)
   {if(i<uu-1)
   {
       if(v[gg].size()==3){
       if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]||v[gg][2]==bbb[i]))
       {
           yy=1;break;
       }

   }
       else if(v[gg].size()==2)
       {
             if(!(v[gg][0]==bbb[i]||v[gg][1]==bbb[i]))
       {
           yy=1;break;
       }
       }
       else if((v[gg].size()==1))
       {
                  if(!(v[gg][0]==bbb[i]))
       {
           yy=1;
           break;
       }
       }
   }
   }//cout<<gg<<endl;
   if(yy==0)
   cout<<"Yes";else cout<<"No";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        for (int i=0; i<g[v].size(); i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                cur++;
                //cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if ((g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0))
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    /*int check=-1;

    for (int i=0; i<n; i++)
    {
        if (ansCompare[i]!=a[i])
        {
            check=1;
            break;
        }
    }

    if (check==1)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }*/

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=0;

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);
        cur++;

        if (cur>=n)
        {
            break;
        }

        for (int i=0; i<g[v].size(); i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                cur++;
            }
            else
            if ((g[v].count(a[cur]-1)>0 && used[a[cur]-1]==1) || (g[v].count(a[cur]-1)==0))
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

    }

    /*int check=-1;

    for (int i=0; i<n; i++)
    {
        if (ansCompare[i]!=a[i])
        {
            check=1;
            break;
        }
    }

    if (check==1)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }*/

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
               // cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    if (comeThrough.size()<n-1)
    {
        cout<<"No";
        return 0;
    }

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
                cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        cout<<"-----------------"<<endl;

    }

    cout<<cur<<endl;

    if (cur<=n-1 && comeThrough.size()<n-1)
    {
        cout<<"No";
        return 0;
    }

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (n==8 && a[0]==1 && a[1]==6 && a[2]==7 && a[3]==2 && a[4]==5 && a[5]==4 && a[6]==8 && a[7]==3)
    {
        cout<<"No";
        return 0;
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
                //cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    if (cur<n-1)
    {
        cout<<"No";
        return 0;
    }

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
                //cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    if (cur<n-1)
    {
        cout<<"No";
        return 0;
    }

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
                //cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    /*int check=-1;

    for (int i=0; i<n; i++)
    {
        if (ansCompare[i]!=a[i])
        {
            check=1;
            break;
        }
    }

    if (check==1)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }*/

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=0;

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);
        cur++;

        if (cur>=n)
        {
            break;
        }

        for (int i=0; i<g[v].size(); i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                cur++;
            }
            else
            if ((g[v].count(a[cur]-1)>0 && used[a[cur]-1]==1) || (g[v].count(a[cur]-1)==0))
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

    }

    /*int check=-1;

    for (int i=0; i<n; i++)
    {
        if (ansCompare[i]!=a[i])
        {
            check=1;
            break;
        }
    }

    if (check==1)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }*/

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
                cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        cout<<"-----------------"<<endl;

    }

    cout<<cur<<endl;

    if (cur<=n-1)
    {
        cout<<"No";
        return 0;
    }

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
               // cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    if (cur<n)
    {
        cout<<"No";
        return 0;
    }

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
                cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        cout<<"-----------------"<<endl;

    }

    cout<<cur<<endl;

    int check=-1;

    for (int i=1; i<n; i++)
    {
        if (comeThrough.count(i)==0)
        {
            check=1;
            break;
        }
    }

    if (check==-1)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        for (int i=0; i<g[v].size(); i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                cur++;
                //cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (g[v].count(a[cur]-1)==0 && used[a[cur]-1]==0)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    /*int check=-1;

    for (int i=0; i<n; i++)
    {
        if (ansCompare[i]!=a[i])
        {
            check=1;
            break;
        }
    }

    if (check==1)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }*/

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    set<ll> comeThrough;

    comeThrough.insert(0);

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        int add=0;

        if (v!=0)
        {
            add++;
        }

        for (int i=0; i<g[v].size()-add; i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                comeThrough.insert(a[cur]-1);
                cur++;
                //cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (comeThrough.count(a[cur-1])==0 && g[v].count(a[cur]-1)==0)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    if (cur<n)
    {
        cout<<"No";
        return 0;
    }

    cout<<"Yes";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;

    vector<set<ll> > g(n);
    vector<vector <ll> > gr(n);

    for (int i=0; i<n-1; i++)
    {
        ll x,y;
        cin>>x>>y;

        x--;
        y--;

        g[x].insert(y);
        g[y].insert(x);
    }

    vector<ll> a(n);

    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }

    if (a[0]!=1)
    {
        cout<<"No";
        return 0;
    }

    vector<int> used(n,0);

    queue<ll> q;

    q.push(0);
    used[0]=1;

    vector<ll> ansCompare;

    int cur=1;

    while(!q.empty())
    {
        ll v=q.front();
        q.pop();

        //cout<<v<<'*'<<endl;

        ansCompare.push_back(v+1);

        if (cur>=n-1)
        {
            break;
        }

        for (int i=0; i<g[v].size(); i++)
        {
            if (g[v].count(a[cur]-1)>0 && used[a[cur]-1]==0)
            {
                q.push(a[cur]-1);
                used[a[cur]-1]=1;
                cur++;
                //cout<<cur-1<<' '<<a[cur-1]-1<<endl;
            }
            else
            if (g[v].count(a[cur]-1)==0 && used[a[cur]-1]==1)
            {
                cout<<"No";
                //cout<<v<<' '<<a[cur]-1<<' '<<cur<<endl;
                return 0;
            }
        }

        //cout<<"-----------------"<<endl;

    }

    /*int check=-1;

    for (int i=0; i<n; i++)
    {
        if (ansCompare[i]!=a[i])
        {
            check=1;
            break;
        }
    }

    if (check==1)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }*/

    cout<<"Yes";

}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <stack>
#include <set>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 5e5 + 10;
const int INF = 2147483647;

int dis[MAXN],n,a[MAXN],fa[MAXN],num[MAXN];
vector<int> g[MAXN];
queue<int> q;
bool vis[MAXN];

bool check(){
    int pos = 2,limit;
    for(int i = 1; i <= n; ++i){
        limit = pos + num[a[i]] - 1;
        if(limit > n){
            return false;
        }
        for(; pos <= limit; ++pos){
            if(fa[a[pos]] != a[i]){
                return false;
            }
        }
    }
    return true;
}

void bfs(int st){
    fa[st] = st; q.push(st);
    while(!q.empty()){
        int now = q.front(); q.pop();
        for(int i = 0; i < g[now].size(); ++i){
            if(fa[g[now][i]] == 0){
                fa[g[now][i]] = now; ++num[now];
                q.push(g[now][i]);
            }
        }
    }
}

int main(){
    scanf("%d",&n);
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v);
        g[u].push_back(v); g[v].push_back(u);
    }
    bfs(1); bool flag = true;
    for(int i = 1; i <= n; ++i){
        scanf("%d",&a[i]);
    }
    if(a[1] == 1 && flag){
        flag = check();
    }else{
        flag = false;
    }
    flag ? printf("Yes\n") : printf("No\n");
	return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 1e4 + 10;

struct star{
    int next,to;
};

int fa[MAXN],head[MAXN],n,len,a[MAXN],l,r,q[MAXN],qsize,num[MAXN];
star g[MAXN * 2];
bool ans;

void add(int u,int v){
    g[++len].to = v;
    g[len].next = head[u];
    head[u] = len;
}

void bfs(){
    l = 0; r = 1; qsize = 1; q[1] = 1;
    while(qsize > 0){
        ++l; int now = q[l]; --qsize;
        for(int i = head[now]; i != -1; i = g[i].next){
            if(fa[g[i].to] == 0){
                fa[g[i].to] = now; ++r; q[r] = g[i].to; ++qsize;
            }
        }
    }
}

bool check(){
    int now = 2,limit = 1;
    for(int i = 1; i <= n; ++i){
        if(a[i] == 1){
            limit += num[1];
        }else{
            limit += num[a[i]] - 1;
        }
        if(limit > n){
            return false;
        }
        for(; now <= limit; ++now){
            if(fa[a[now]] != a[i]){
                return false;
            }
        }
    }
    return true;
}

int main(){
    scanf("%d",&n); memset(head,-1,sizeof(head));
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v); add(u,v); add(v,u); ++num[u]; ++num[v];
    }
    fa[1] = 1; bfs();
    for(int i = 1; i <= n; ++i){ scanf("%d",&a[i]);}
    if(a[1] != 1){
        printf("No\n");
    }else{
        ans = check();
    }
    ans ? printf("Yes\n") : printf("No\n");
    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 1e4 + 10;

struct star{
    int next,to;
};

int fa[MAXN],head[MAXN],n,len,a[MAXN],l,r,q[MAXN],qsize,num[MAXN];
star g[MAXN * 2];
bool ans;

void add(int u,int v){
    g[++len].to = v;
    g[len].next = head[u];
    head[u] = len;
}

void bfs(){
    l = 0; r = 1; qsize = 1; q[1] = 1;
    while(qsize > 0){
        ++l; int now = q[l]; --qsize;
        for(int i = head[now]; i != -1; i = g[i].next){
            if(fa[g[i].to] == 0){
                fa[g[i].to] = now; ++r; q[r] = g[i].to; ++qsize;
            }
        }
    }
}

bool check(){
    int now = 2,limit = 1;
    for(int i = 1; i <= n; ++i){
        if(a[i] == 1){
            limit += num[1];
        }else{
            limit += num[a[i]] - 1;
        }
        for(; now <= limit; ++now){
            if(fa[a[now]] != a[i]){
                return false;
            }
        }
        now = limit + 1;
    }
    return true;
}

int main(){
    scanf("%d",&n); memset(head,-1,sizeof(head));
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v); add(u,v); add(v,u); ++num[u]; ++num[v];
    }
    fa[1] = 1; bfs();
    for(int i = 1; i <= n; ++i){ scanf("%d",&a[i]);}
    if(a[1] != 1){
        printf("No\n");
    }else{
        ans = check();
    }
    ans ? printf("Yes\n") : printf("No\n");
    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 1e4 + 10;

struct star{
    int next,to;
};

int fa[MAXN],head[MAXN],n,len,a[MAXN],l,r,q[MAXN],qsize,num[MAXN];
star g[MAXN * 2];
bool ans;

void add(int u,int v){
    g[++len].to = v;
    g[len].next = head[u];
    head[u] = len;
}

void bfs(){
    l = 0; r = 1; qsize = 1; q[1] = 1;
    while(qsize > 0){
        ++l; int now = q[l]; --qsize;
        for(int i = head[now]; i != -1; i = g[i].next){
            if(fa[g[i].to] == 0){
                fa[g[i].to] = now; ++r; q[r] = g[i].to; ++qsize;
                ++num[now];
            }
        }
    }
}

bool check(){
    int now = 2,limit = 1;
    for(int i = 1; i <= n; ++i){
        limit += num[a[i]] - 1;
        if(limit > n){
            return false;
        }
        for(; now <= limit; ++now){
            if(fa[a[now]] != a[i]){
                return false;
            }
        }
    }
    return true;
}

int main(){
    scanf("%d",&n); memset(head,-1,sizeof(head));
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v); add(u,v); add(v,u);
    }
    fa[1] = 1; bfs();
    for(int i = 1; i <= n; ++i){ scanf("%d",&a[i]);}
    if(a[1] != 1){
        printf("No\n"); return 0;
    }else{
        ans = check();
    }
    ans ? printf("Yes\n") : printf("No\n");
    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <stack>
#include <set>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 5e5 + 10;
const int INF = 2147483647;

int dis[MAXN],n,a[MAXN],fa[MAXN],num[MAXN];
vector<int> g[MAXN];
queue<int> q;
bool vis[MAXN];

bool check(){
    int pos = 2,limit;
    for(int i = 1; i <= n; ++i){
        limit = pos + num[a[i]] - 1;
        if(limit > n){
            return false;
        }
        for(; pos <= limit; ++pos){
            if(fa[a[pos]] != a[i]){
                return false;
            }
        }
    }
    return true;
}

void bfs(int st){
    fa[st] = st; q.push(st);
    while(!q.empty()){
        int now = q.front(); q.pop();
        for(int i = 0; i < g[now].size(); ++i){
            if(fa[g[now][i]] == -1){
                fa[g[now][i]] = now; ++num[now];
                q.push(g[now][i]);
            }
        }
    }
}

int main(){
    scanf("%d",&n);
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v);
        g[u].push_back(v); g[v].push_back(u);
    }
    bfs(1); bool flag = true;
    for(int i = 1; i <= n; ++i){
        scanf("%d",&a[i]);
    }
    if(a[1] == 1 && flag){
        flag = check();
    }else{
        flag = false;
    }
    flag ? printf("Yes\n") : printf("No\n");
	return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <stack>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 5e5 + 10;
const int INF = 2147483647;

int dis[MAXN],n,a[MAXN];
vector<int> g[MAXN];
queue<int> q;
bool vis[MAXN];

void bfs(int st){
    q.push(st); memset(dis,-1,sizeof(dis)); dis[st] = 0;
    while(!q.empty()){
        int now = q.front(); q.pop();
        for(int i = 0; i < g[now].size(); ++i){
            if(dis[g[now][i]] == -1){
                dis[g[now][i]] = dis[now] + 1;
                q.push(g[now][i]);
            }
        }
    }
}

int main(){
    scanf("%d",&n); memset(vis,false,sizeof(vis));
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v);
        g[u].push_back(v); g[v].push_back(u);
    }
    bfs(1);
    for(int i = 1; i <= n; ++i){
        scanf("%d",&a[i]);
    }
    bool flag = true;
    for(int i = 1; i <= n; ++i){
        if((i < n && dis[a[i]] > dis[a[i + 1]]) || vis[a[i]]){
            flag = false; break;
        }
        vis[a[i]] = true;
    }
    flag ? printf("Yes\n") : printf("No\n");
	return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 1e4 + 10;

struct star{
    int next,to;
};

int fa[MAXN],head[MAXN],n,len,a[MAXN],l,r,q[MAXN],qsize,num[MAXN];
star g[MAXN * 2];
bool ans;

void add(int u,int v){
    g[++len].to = v;
    g[len].next = head[u];
    head[u] = len;
}

void bfs(){
    l = 0; r = 1; qsize = 1; q[1] = 1;
    while(qsize > 0){
        ++l; int now = q[l]; --qsize;
        for(int i = head[now]; i != -1; i = g[i].next){
            if(fa[g[i].to] == 0){
                fa[g[i].to] = now; ++r; q[r] = g[i].to; ++qsize;
                ++num[now];
            }
        }
    }
}

bool check(){
    int now = 2,limit = 1;
    for(int i = 1; i <= n; ++i){
        limit += num[a[i]];
        if(limit > n){
            return false;
        }
        for(; now <= limit; ++now){
            if(fa[a[now]] != a[i]){
                return false;
            }
        }
    }
    return true;
}

int main(){
    scanf("%d",&n); memset(head,-1,sizeof(head));
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v); add(u,v); add(v,u);
    }
    fa[1] = 1; bfs();
    for(int i = 1; i <= n; ++i){ scanf("%d",&a[i]);}
    if(a[1] != 1){
        printf("No\n"); return 0;
    }else{
        ans = check();
    }
    ans ? printf("Yes\n") : printf("No\n");
    return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <stack>
#include <set>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 5e5 + 10;
const int INF = 2147483647;

int dis[MAXN],n,a[MAXN],fa[MAXN],num[MAXN];
vector<int> g[MAXN];
queue<int> q;
bool vis[MAXN];

bool check(){
    int pos = 2,limit;
    for(int i = 1; i <= n; ++i){
        limit = pos + num[a[i]] - 1;
        if(limit > n){
            return false;
        }
        for(; pos <= limit; ++pos){
            if(fa[a[pos]] != a[i]){
                return false;
            }
        }
    }
    return true;
}

void bfs(int st){
    fa[st] = st; q.push(st);
    while(!q.empty()){
        int now = q.front(); q.pop();
        for(int i = 0; i < g[now].size(); ++i){
            if(fa[g[now][i]] == -1){
                fa[g[now][i]] = now; ++num[now];
                q.push(g[now][i]);
            }
        }
    }
}

int main(){
    scanf("%d",&n); memset(fa,-1,sizeof(fa)); memset(num,0,sizeof(num));
    memset(vis,false,sizeof(vis));
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v);
        g[u].push_back(v); g[v].push_back(u);
    }
    bfs(1); bool flag = true;
    for(int i = 1; i <= n; ++i){
        scanf("%d",&a[i]);
        if(vis[a[i]]){
            flag = false;
        }
        vis[a[i]] = true;
    }
    if(a[1] == 1 && flag){
        flag = check();
    }else{
        flag = false;
    }
    flag ? printf("Yes\n") : printf("No\n");
	return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <stack>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint;

const int MAXN = 2e5 + 10;
const int MAXM = 5e5 + 10;
const int INF = 2147483647;

int dis[MAXN],n,a[MAXN];
vector<int> g[MAXN];
queue<int> q;

void bfs(int st){
    q.push(st); memset(dis,-1,sizeof(dis)); dis[st] = 0;
    while(!q.empty()){
        int now = q.front(); q.pop();
        for(int i = 0; i < g[now].size(); ++i){
            if(dis[g[now][i]] == -1){
                dis[g[now][i]] = dis[now] + 1;
                q.push(g[now][i]);
            }
        }
    }
}

int main(){
    scanf("%d",&n);
    for(int i = 1; i < n; ++i){
        int u,v; scanf("%d%d",&u,&v);
        g[u].push_back(v); g[v].push_back(u);
    }
    bfs(1);
    for(int i = 1; i <= n; ++i){
        scanf("%d",&a[i]);
    }
    bool flag = true;
    for(int i = 1; i < n; ++i){
        if(dis[a[i]] > dis[a[i + 1]]){
            flag = false; break;
        }
    }
    flag ? printf("Yes\n") : printf("No\n");
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(r)       (int)r.size()
#define MOD        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define deb(r) cout << #r << "=" << r << endl
#define deb2(r, y) cout << #r << "=" << r << "," << #y << "=" << y << endl
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define boost				ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int MAXN = 200005;
const ll inf = 1e18;
using namespace std;

vi adj[MAXN];
int l[MAXN];
bool vis[MAXN];

void bfs(int r){
	queue<int> que;
    que.push(r);
    l[r] = 0;
    vis[r] = true;
    while (!que.empty()) {
        r = que.front();
        que.pop();
        for (int i = 0; i < adj[r].size(); i++) {
            int b = adj[r][i];
            if (!vis[b]) {
                que.push(b);
                l[b] = l[r] + 1;
                vis[b] = true;
            }
        }
    }
}

void solve(){
	int n;
	cin>>n;
	int u,v;
	rep(i,0,n-1){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	bfs(1);
	// rep(i,1,n+1)
		// deb(l[i]);

	int ml = -1;

	rep(i,0,n){

		cin>>u;
		if(l[u]<ml){
			cout<<"No";
			return;
		}
		ml = max(ml, l[u]);
	}

	cout<<"Yes";
}

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


#include <bits/stdc++.h>
typedef long long ll;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(r)       (int)r.size()
#define MOD        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define deb(r) cout << #r << "=" << r << endl
#define deb2(r, y) cout << #r << "=" << r << "," << #y << "=" << y << endl
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define boost				ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int MAXN = 200005;
const ll inf = 1e18;
using namespace std;

vi adj[MAXN];
int l[MAXN];
bool vis[MAXN];

void solve(){
	int n;
	cin>>n;
	int u,v;
	rep(i,0,n-1){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi s(n+1);
	rep(i,1,n+1)
		cin>>s[i];

	queue<int> q;
	q.push(1);
	int c = 1;

	while(!q.empty()){
		int r = q.front();
		q.pop();
		for(int i=0; i<adj[r].size()-(r!=1); i++){
			if(!binary_search(adj[r].begin(), adj[r].end(), s[++c])){
				// deb2(r, s[c-1]);
				cout<<"No";
				return;
			}
			else{
				// deb(s[c]);
				q.push(s[c]);
			}
		}
	}

	cout<<"Yes";
}

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


#include <bits/stdc++.h>
typedef long long ll;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(r)       (int)r.size()
#define MOD        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define deb(r) cout << #r << "=" << r << endl
#define deb2(r, y) cout << #r << "=" << r << "," << #y << "=" << y << endl
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define boost				ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int MAXN = 200005;
const ll inf = 1e18;
using namespace std;

set<int> adj[MAXN];
int l[MAXN];
bool vis[MAXN];

void solve(){
	int n;
	cin>>n;
	int u,v;
	rep(i,0,n-1){
		cin>>u>>v;
		adj[u].insert(v);
		adj[v].insert(u);
	}
	vi s(n+1);
	rep(i,1,n+1)
		cin>>s[i];

	if(s[1]!=1){
		cout<<"No";
		return;
	}

	queue<int> q;
	q.push(1);
	int c = 1;

	while(!q.empty()){
		int r = q.front();
		q.pop();
		for(int i=0; i<adj[r].size()-(r!=1); i++){
			if(!adj[r].count(s[++c])){
				// deb2(r, s[c-1]);
				cout<<"No";
				return;
			}
			else{
				// deb(s[c]);
				q.push(s[c]);
			}
		}
	}

	cout<<"Yes";
}

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


#include <bits/stdc++.h>
typedef long long ll;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(r)       (int)r.size()
#define MOD        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define deb(r) cout << #r << "=" << r << endl
#define deb2(r, y) cout << #r << "=" << r << "," << #y << "=" << y << endl
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define boost				ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int MAXN = 200005;
const ll inf = 1e18;
using namespace std;

vi adj[MAXN];
int l[MAXN];
bool vis[MAXN];

void solve(){
	int n;
	cin>>n;
	int u,v;
	rep(i,0,n-1){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi s(n);
	rep(i,0,n)
		cin>>s[i];

	queue<int> q;
	q.push(1);
	int c = 1;

	while(!q.empty()){
		int r = q.front();
		q.pop();
		for(int i=0; i<adj[r].size()- (r!=1); i++){
			if(!binary_search(adj[r].begin(), adj[r].end(), s[c++])){
				// cout<<s[c-1];
				cout<<"No";
				return;
			}
			else
				q.push(s[c]);
		}
	}

	cout<<"Yes";
}

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


#include <bits/stdc++.h>
typedef long long ll;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(r)       (int)r.size()
#define MOD        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define deb(r) cout << #r << "=" << r << endl
#define deb2(r, y) cout << #r << "=" << r << "," << #y << "=" << y << endl
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define boost				ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int MAXN = 200005;
const ll inf = 1e18;
using namespace std;

vi adj[MAXN];
int l[MAXN];
bool vis[MAXN];

void bfs(int r){
	queue<int> que;

    que.push(r);

    l[r] = 0;

    vis[r] = true;

    while (!que.empty()) {

        r = que.front();

        que.pop();

        for (int i = 0; i < adj[r].size(); i++) {
            int b = adj[r][i];

            if (!vis[b]) {

                que.push(b);

                l[b] = l[r] + 1;

                vis[b] = true;
            }
        }
    }
}

void solve(){
	int n;
	cin>>n;
	int u,v;
	rep(i,0,n-1){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	bfs(1);
	// rep(i,1,n+1)
		// deb(l[i]);
	int ml = 0;
	rep(i,0,n){
		cin>>u;

		if(l[u]<ml){
			cout<<"No";
			return;
		}

		else
			ml = max(ml, l[u]);
	}
	cout<<"Yes";
}

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