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

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 2e5+5,inf = 1e9+7;
set<int>st[N];
int vis[N],Arr[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;cin>>n;
    int m = n-1;
    while(m--)
    {
        int u,v;cin>>u>>v;
        st[u].insert(v);
        st[v].insert(u);
    }
    for(int i=1;i<=n;i++)
        cin>>Arr[i];
    int id = 1;
    queue<int>q1;
    q1.push(1);
    vis[1] = 1;
    if( Arr[id]!=1 )cout<< "No\n",exit(0);
    while(!q1.empty())
    {
        int u = q1.front();
        //if( u!=Arr[id++] )cout<< "No\n",exit(0);
        q1.pop();
        for(auto v:st[u])
        {
            if( id>=n )break;
            if( !vis[Arr[id+1]]&&st[u].find(Arr[id+1])!=st[u].end() )
            {
                st[Arr[id+1]].erase(u);
                vis[Arr[id+1]]=vis[u]+1;
                q1.push(Arr[++id]);
            }
            else if( !vis[Arr[id+1]] )
            {
                cout<< "No\n",exit(0);
            }
        }
    }
//    for(int i=1;i<n;i++)
//    {
//        if( vis[ Arr[i] ]>vis[ Arr[i+1] ] )
//            cout<< "No\n",exit(0);
//    }
    cout<< "Yes\n";

    // main();

    return 0;
}


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

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 2e5+5,inf = 1e9+7;
set<int>st[N];
int vis[N],Arr[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;cin>>n;
    int m = n-1;
    while(m--)
    {
        int u,v;cin>>u>>v;
        st[u].insert(v);
        st[v].insert(u);
    }
    for(int i=1;i<=n;i++)
        cin>>Arr[i];
    int id = 1;
    queue<int>q1;
    q1.push(1);
    vis[1] = 1;
    if( Arr[id]!=1 )cout<< "No\n",exit(0);
    while(!q1.empty())
    {
        int u = q1.front();
        //if( u!=Arr[id++] )cout<< "No\n",exit(0);
        q1.pop();
        for(auto v:st[u])
        {
            if( id>=n )break;
            if( !vis[Arr[id+1]]&&st[u].find(Arr[id+1])!=st[u].end() )
            {
                vis[Arr[id+1]]=vis[u]+1;
                q1.push(Arr[id++]);
            }
            else if( !vis[Arr[id+1]] )
            {
                cout<< "No\n",exit(0);
            }
        }
    }
//    for(int i=1;i<n;i++)
//    {
//        if( vis[ Arr[i] ]>vis[ Arr[i+1] ] )
//            cout<< "No\n",exit(0);
//    }
    cout<< "Yes\n";

    // main();

    return 0;
}


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

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 2e5+5,inf = 1e9+7;
set<int>st[N];
int vis[N],Arr[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;cin>>n;
    int m = n-1;
    while(m--)
    {
        int u,v;cin>>u>>v;
        st[u].insert(v);
        st[v].insert(u);
    }
    for(int i=1;i<=n;i++)
        cin>>Arr[i];
    int id = 1;
    queue<int>q1;
    q1.push(1);
    vis[1] = 1;
    while(!q1.empty())
    {
        int u = q1.front();
        //if( u!=Arr[id++] )cout<< "No\n",exit(0);
        q1.pop();
        for(auto v:st[u])
        {
            if( !vis[v] )
            {
                vis[v]=vis[u]+1,q1.push(v);
            }
        }
    }
    for(int i=1;i<n;i++)
    {
        if( vis[ Arr[i] ]>vis[ Arr[i+1] ] )
            cout<< "No\n",exit(0);
    }
    cout<< "Yes\n";

    // main();

    return 0;
}


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

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 2e5+5,inf = 1e9+7;
set<int>st[N];
int vis[N],Arr[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;cin>>n;
    int m = n-1;
    while(m--)
    {
        int u,v;cin>>u>>v;
        st[u].insert(v);
        st[v].insert(u);
    }
    for(int i=1;i<=n;i++)
        cin>>Arr[i];
    int id = 1;
    queue<int>q1;
    q1.push(1);
    vis[1] = 1;
    while(!q1.empty())
    {
        int u = q1.front();
        //if( u!=Arr[id++] )cout<< "No\n",exit(0);
        q1.pop();
        for(auto v:st[u])
        {
            if( !vis[v] )
            {
                vis[v]=vis[u]+1,q1.push(v);
            }
        }
    }
    for(int i=1;i<n;i++)
    {
        if( vis[ Arr[i] ]>vis[ Arr[i+1] ] )
            cout<< "No\n";
    }
    cout<< "Yes\n";

    // main();

    return 0;
}


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

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 2e5+5,inf = 1e9+7;
set<int>st[N];
int vis[N],Arr[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;cin>>n;
    int m = n-1;
    while(m--)
    {
        int u,v;cin>>u>>v;
        st[u].insert(v);
        st[v].insert(u);
    }
    for(int i=1;i<=n;i++)
        cin>>Arr[i];
    int id = 1;
    queue<int>q1;
    q1.push(1);
    vis[1] = 1;
    if( Arr[id]!=1 )cout<< "No\n",exit(0);
    while(!q1.empty())
    {
        int u = q1.front();
        //if( u!=Arr[id++] )cout<< "No\n",exit(0);
        q1.pop();
        for(auto v:st[u])
        {
            if( !vis[Arr[++id]]&&st[u].find(Arr[id])!=st[u].end() )
            {
                vis[Arr[id]]=vis[u]+1;
                q1.push(Arr[id]);
            }
            else if( !vis[Arr[id]] )
            {
                cout<< "No\n",exit(0);
            }
        }
    }
//    for(int i=1;i<n;i++)
//    {
//        if( vis[ Arr[i] ]>vis[ Arr[i+1] ] )
//            cout<< "No\n",exit(0);
//    }
    cout<< "Yes\n";

    // main();

    return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define  endl    '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
map<int,int> order;
map<int,int> level;
map<int,int> parent;
int a[200005];
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    queue<pii> q;

    //int x,y;
    pii p;
    int cnt=0;
    //cout<<cnt;
    q.push(make_pair(1,1));
    while(!q.empty())
    {
        p=q.front();
        q.pop();
        x=p.first;
        y=p.second;
        visited[x]=1;
        level[x]=y;
        cnt=y;
        for(int i=0;i<adj[x].size();i++)
        {
            parent[adj[x][i]]=x;
            if(visited[adj[x][i]]==0)
            q.push(make_pair(adj[x][i],y+1));
        }
    }
    //cout<<cnt;
    for(int i=0;i<n;i++)
    cin>>a[i];

    //cout<<a[0];
    if(a[0]!=1)
    {
        cout<<"NO";
        return 0;
    }
    int flag=0,curr=2;
    for(int i=2;i<n;i++)
    {
        if(level[a[i]]>curr)
        {
            curr=level[a[i]];
        }
        else if(level[a[i]]<curr)
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
        return 0;
    }
    cnt=1;
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==2)
        {
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }

        }
        else
        {
            x=i;
            break;
        }
    }
    int res=2;
    curr=1;
    cnt=1;
    flag=0;
    //cout<<x;
    //cout<<level[a[3]];
    //order[parent[a[3]]];
    for(int i=x;i<n;i++)
    {
        if(level[a[i]]==res+1)
        {
            res+=1;
            curr=1;
            cnt=1;
        }
        //cout<<order[parent[a[3]]]<<parent[a[3]];
        //cout<<order[parent[a[i]]]<<" "<<curr<<endl;
        if(order[parent[a[i]]]==curr)
        {
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }

        }
        else if(order[parent[a[i]]]<curr)
        {
            //cout<<"flag";
            flag=1;
            break;
        }
        else
        {
            curr++;
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
int a[200005],b[200005];

bool cmp(int i,int j)
{
    if(b[i]>b[j])
    return (0);
    else
    return (1);
}
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;

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

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

    for(int i=1;i<n;i++)
    sort(all(adj[i]),cmp);

    queue<int> q;

    vi v;

    q.push(1);

    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        visited[x]=1;
        v.pb(x);

        for(int i=0;i<adj[x].size();i++)
        {
            if(visited[adj[x][i]]==0)
            q.push(adj[x][i]);
        }
    }
    int flag=0;
    for(int i=0;i<=n;i++)
    {
        if(a[i]!=v[i])
        flag=1;
    }
    if(a[0]!=1)
    flag=1;

    if(flag)
    cout<<"NO";
    else
    cout<<"YES";
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define  endl    '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
map<int,int> order;
map<int,int> level;
map<int,int> parent;
int a[200005];
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    queue<pii> q;

    //int x,y;
    pii p;
    int cnt=0;
    //cout<<cnt;
    q.push(make_pair(1,1));
    while(!q.empty())
    {
        p=q.front();
        q.pop();
        x=p.first;
        y=p.second;
        visited[x]=1;
        level[x]=y;
        cnt=y;
        for(int i=0;i<adj[x].size();i++)
        {
            parent[adj[x][i]]=x;
            if(visited[adj[x][i]]==0)
            q.push(make_pair(adj[x][i],y+1));
        }
    }
    //cout<<cnt;
    for(int i=0;i<n;i++)
    cin>>a[i];

    //cout<<a[0];
    if(a[0]!=1)
    {
        cout<<"NO";
        return 0;
    }
    int flag=0,curr=2;
    for(int i=2;i<n;i++)
    {
        if(level[a[i]]>curr)
        {
            curr=level[a[i]];
        }
        else if(level[a[i]]<curr)
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
        return 0;
    }
    cnt=1;
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==2)
        {
            //if(adj[a[i]].size()>1)

                order[a[i]]=cnt;
                cnt++;

        }
        else
        {
            x=i;
            break;
        }
    }
    int res=2;
    curr=1;
    cnt=1;
    flag=0;
    //cout<<x;
    //cout<<level[a[3]];
    //order[parent[a[3]]];
    for(int i=x;i<n;i++)
    {
        if(level[a[i]]==res+1)
        {
            res+=1;
            curr=1;
            cnt=1;
        }
        //cout<<order[parent[a[3]]]<<parent[a[3]];
        //cout<<order[parent[a[i]]]<<" "<<curr<<endl;
        if(order[parent[a[i]]]==curr)
        {
                order[a[i]]=cnt;
                cnt++;

        }
        else if(order[parent[a[i]]]<curr)
        {
            //cout<<"flag";
            flag=1;
            break;
        }
        else
        {
            curr++;
            order[a[i]]=cnt;
            cnt++;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define  endl    '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
map<int,int> order;
map<int,int> level;
map<int,int> parent;
int a[200005];
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    queue<pii> q;

    //int x,y;
    pii p;
    int cnt=0;
    //cout<<cnt;
    q.push(make_pair(1,1));
    while(!q.empty())
    {
        p=q.front();
        q.pop();
        x=p.first;
        y=p.second;
        visited[x]=1;
        level[x]=y;
        cnt=y;
        for(int i=0;i<adj[x].size();i++)
        {
            parent[adj[x][i]]=x;
            if(visited[adj[x][i]]==0)
            q.push(make_pair(adj[x][i],y+1));
        }
    }
    //cout<<cnt;
    for(int i=0;i<n;i++)
    cin>>a[i];

    //cout<<a[0];
    if(a[0]!=1)
    {
        cout<<"NO";
        return 0;
    }
    int flag=0,curr=1;
    for(int i=0;i<n;i++)
    {
        if(level[a[i]]==curr+1)
        {
            curr=level[a[i]];
        }
        else if(level[a[i]]==curr)
        continue;
        else
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
        return 0;
    }

    int res=1;
    curr=1;
    cnt=1;
    flag=0;
    parent[1]=1;
    order[1]=1;
    //cout<<x;
    //cout<<level[a[3]];
    //order[parent[a[3]]];
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==res+1)
        {
            res+=1;
            curr=1;
            cnt=1;
        }
        //cout<<order[parent[a[3]]]<<parent[a[3]];
        //cout<<order[parent[a[i]]]<<" "<<curr<<endl;
        if(order[parent[a[i]]]==curr)
        {
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }

        }
        else if(order[parent[a[i]]]==curr+1)
        {
            curr++;
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }
        }
        else
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005],v[200005];
int visited[200005]={0};
int a[200005],parentorder[200005],level[200005],b[200005];
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;

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

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

    queue<pii> q;

    q.push(make_pair(1,1));
    int cnt;
    while(!q.empty())
    {
        pii p=q.front();
        int x=p.first;
        int y=p.second;
        q.pop();
        visited[x]=1;
        cnt=y;
        for(int i=0;i<adj[x].size();i++)
        {
            if(visited[adj[x][i]]==0)
            {
                q.push(make_pair(adj[x][i],y+1));
                parentorder[adj[x][i]]=b[x];
                level[adj[x][i]]=y+1;
                v[y+1].pb(adj[x][i]);
            }
        }
    }
    int flag=0;
    if(a[0]!=1)
    flag=1;

    int curr=1;
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==curr)
        continue;
        else if(level[a[i]]==curr+1)
        curr++;
        else
        {
            //cout<<a[i];
            flag=1;
            break;
        }
    }
    //cout<<flag;
    int res;

    for(int i=2;i<=cnt;i++)
    {
        if(v[i].size()>0)
        res=parentorder[v[i][0]];
        //cout<<res;
        for(int j=1;j<v[i].size();j++)
        {
            if(parentorder[v[i][j]]<res)
            {
                //cout<<v[i][j];
                flag=1;
                break;
            }
            else
            {
                res=parentorder[v[i][j]];
            }

        }
    }
    //cout<<flag;
    if(flag)
    cout<<"NO";
    else
    cout<<"YES";
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define  endl    '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
map<int,int> order;
map<int,int> level;
map<int,int> parent;
int a[200005];
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    queue<pii> q;

    //int x,y;
    pii p;
    int cnt=0;
    //cout<<cnt;
    q.push(make_pair(1,1));
    while(!q.empty())
    {
        p=q.front();
        q.pop();
        x=p.first;
        y=p.second;
        visited[x]=1;
        level[x]=y;
        cnt=y;
        for(int i=0;i<adj[x].size();i++)
        {
            parent[adj[x][i]]=x;
            if(visited[adj[x][i]]==0)
            q.push(make_pair(adj[x][i],y+1));
        }
    }
    //cout<<cnt;
    for(int i=0;i<n;i++)
    cin>>a[i];

    //cout<<a[0];
    if(a[0]!=1)
    {
        cout<<"NO";
        return 0;
    }
    int flag=0,curr=2;
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==curr+1)
        {
            curr=level[a[i]];
        }
        else if(level[a[i]]==curr)
        continue;
        else
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
        return 0;
    }
    cnt=1;
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==2)
        {
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }

        }
        else
        {
            x=i;
            break;
        }
    }
    int res=2;
    curr=1;
    cnt=1;
    flag=0;
    //cout<<x;
    //cout<<level[a[3]];
    //order[parent[a[3]]];
    for(int i=x;i<n;i++)
    {
        if(level[a[i]]==res+1)
        {
            res+=1;
            curr=1;
            cnt=1;
        }
        //cout<<order[parent[a[3]]]<<parent[a[3]];
        //cout<<order[parent[a[i]]]<<" "<<curr<<endl;
        if(order[parent[a[i]]]==curr)
        {
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }

        }
        else if(order[parent[a[i]]]==curr+1)
        {
            curr++;
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }
        }
        else
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005],v[200005];
int visited[200005]={0};
int a[200005],parentorder[200005],level[200005],b[200005];
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;

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

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

    queue<pii> q;

    q.push(make_pair(1,1));
    int cnt;
    while(!q.empty())
    {
        pii p=q.front();
        int x=p.first;
        int y=p.second;
        q.pop();
        visited[x]=1;
        level[x]=y;
        v[y].pb(x);
        cnt=y;
        for(int i=0;i<adj[x].size();i++)
        {
            parentorder[adj[x][i]]=b[x];
            if(visited[adj[x][i]]==0)
            {
                q.push(make_pair(adj[x][i],y+1));
            }
        }
    }
    int flag=0;
    if(a[0]!=1)
    flag=1;

    int curr=1;
    for(int i=0;i<n;i++)
    {
        if(level[a[i]]==curr)
        continue;
        else if(level[a[i]]==curr+1)
        curr++;
        else
        {
            flag=1;
            break;
        }
    }
    int res;
    for(int i=1;i<=cnt;i++)
    {
        if(v[i].size()>0)
        res=parentorder[v[i][0]];
        for(int j=1;j<v[i].size();j++)
        {
            if(parentorder[v[i][j]]<res)
            {
                flag=1;
                break;
            }
            else
            {
                res=parentorder[v[i][j]];
            }

        }
    }
    if(flag)
    cout<<"NO";
    else
    cout<<"YES";
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
int a[200005],b[200005];

bool cmp(int i,int j)
{
    if(b[i]>b[j])
    return (0);
    else
    return (1);
}
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;

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

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

    for(int i=1;i<=n;i++)
    sort(all(adj[i]),cmp);

    queue<int> q;

    vi v;

    q.push(1);

    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        visited[x]=1;
        v.pb(x);

        for(int i=0;i<adj[x].size();i++)
        {
            if(visited[adj[x][i]]==0)
            q.push(adj[x][i]);
        }
    }
    int flag=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=v[i])
        flag=1;
    }
    if(a[0]!=1)
    flag=1;

    if(flag)
    cout<<"NO";
    else
    cout<<"YES";
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define  endl    '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
map<int,int> order;
map<int,int> level;
map<int,int> parent;
int a[200005];
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    queue<pii> q;

    //int x,y;
    pii p;
    int cnt=0;
    //cout<<cnt;
    q.push(make_pair(1,1));
    while(!q.empty())
    {
        p=q.front();
        q.pop();
        x=p.first;
        y=p.second;
        visited[x]=1;
        level[x]=y;
        cnt=y;
        for(int i=0;i<adj[x].size();i++)
        {
            parent[adj[x][i]]=x;
            if(visited[adj[x][i]]==0)
            q.push(make_pair(adj[x][i],y+1));
        }
    }
    //cout<<cnt;
    for(int i=0;i<n;i++)
    cin>>a[i];

    //cout<<a[0];
    if(a[0]!=1)
    {
        cout<<"NO";
        return 0;
    }
    int flag=0,curr=2;
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==curr+1)
        {
            curr=level[a[i]];
        }
        else
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
        return 0;
    }
    cnt=1;
    for(int i=1;i<n;i++)
    {
        if(level[a[i]]==2)
        {
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }

        }
        else
        {
            x=i;
            break;
        }
    }
    int res=2;
    curr=1;
    cnt=1;
    flag=0;
    //cout<<x;
    //cout<<level[a[3]];
    //order[parent[a[3]]];
    for(int i=x;i<n;i++)
    {
        if(level[a[i]]==res+1)
        {
            res+=1;
            curr=1;
            cnt=1;
        }
        //cout<<order[parent[a[3]]]<<parent[a[3]];
        //cout<<order[parent[a[i]]]<<" "<<curr<<endl;
        if(order[parent[a[i]]]==curr)
        {
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }

        }
        else if(order[parent[a[i]]]==curr+1)
        {
            curr++;
            if(adj[a[i]].size()>1)
            {
                order[a[i]]=cnt;
                cnt++;
            }
        }
        else
        {
            flag=1;
            break;
        }
    }
    //cout<<flag;
    if(flag)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vi adj[200005];
int visited[200005]={0};
int a[200005],b[200005];

bool cmp(int i,int j)
{
    if(b[i]>b[j])
    return (0);
    else
    return (1);
}
int main()
{
    ios
    int n;
    cin>>n;
    int x,y;

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

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

    for(int i=1;i<n;i++)
    sort(all(adj[i]),cmp);

    queue<int> q;

    vi v;

    q.push(1);

    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        visited[x]=1;
        v.pb(x);

        for(int i=0;i<adj[x].size();i++)
        {
            if(visited[adj[x][i]]==0)
            q.push(adj[x][i]);
        }
    }
    int flag=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=v[i])
        flag=1;
    }
    if(a[0]!=1)
    flag=1;

    if(flag)
    cout<<"NO";
    else
    cout<<"YES";
}


//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        bool zz=0;
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
                //cout<<par<<'\n';
                //cout<<'*'<<lev<<'\n';
                //cout<<vis<<i<<'\n';
                /*if(lev[b[i]-1]!=lev[b[i-1]-1]&&!vis[b[i-1]-1])
                    return cout<<"No",0;*/
                if(zz)
                if(vis[b[i-1]-1]>vis[b[i]-1])
                    return cout<<"No",0;
                if(lev[b[i]-1]!=lev[b[i-1]-1])
                    zz=1;
            }
        }
    }
    cout<<"Yes";
}


//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
                //cout<<par<<'\n';
                //cout<<'*'<<lev<<'\n';
                //cout<<vis<<i<<'\n';
                /*if(lev[b[i]-1]!=lev[b[i-1]-1]&&!vis[b[i-1]-1])
                    return cout<<"No",0;*/
                if(vis[b[i]-1]&&vis[b[i-1]-1]&&vis[b[i-1]-1]>vis[b[i]-1])
                    return cout<<"No",0;
            }
        }
    }
    cout<<"Yes";
}


//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        bool zz=0;
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
                //cout<<par<<'\n';
                //cout<<'*'<<lev<<'\n';
                //cout<<vis<<i<<'\n';
                /*if(lev[b[i]-1]!=lev[b[i-1]-1]&&!vis[b[i-1]-1])
                    return cout<<"No",0;*/
                if(zz)
                if(vis[b[i-1]-1]&&vis[b[i]-1]&&vis[b[i-1]-1]>vis[b[i]-1])
                    return cout<<"No",0;
                if(lev[b[i]-1]!=lev[b[i-1]-1])
                    zz=1;
            }
        }
    }
    cout<<"Yes";
}


// I should have read the announcement.

//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        bool zz=0;
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
                //cout<<par<<'\n';
                //cout<<'*'<<lev<<'\n';
                //cout<<vis<<i<<'\n';
                /*if(lev[b[i]-1]!=lev[b[i-1]-1]&&!vis[b[i-1]-1])
                    return cout<<"No",0;*/
            }
            if(lev[b[i]-1]!=lev[b[i-1]-1])
                zz=1;
            //cout<<'*'<<vis[b[i-1]-1]<<' '<<vis[b[i]-1]<<'\n';
            if(zz)
            if(vis[b[i-1]-1]&&vis[b[i]-1]&&vis[b[i-1]-1]>vis[b[i]-1])
                return cout<<"No",0;
        }
    }
    cout<<"Yes";
}


// I should have read the announcement.

//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    //if(b[0]!=1)
        //return cout<<"No",0;
    //else
    {
        dfs(b[0]-1,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        bool zz=0;
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
                //cout<<par<<'\n';
                //cout<<'*'<<lev<<'\n';
                //cout<<vis<<i<<'\n';
                /*if(lev[b[i]-1]!=lev[b[i-1]-1]&&!vis[b[i-1]-1])
                    return cout<<"No",0;*/
                if(zz)
                if(vis[b[i-1]-1]&&vis[b[i]-1]&&vis[b[i-1]-1]>vis[b[i]-1])
                    return cout<<"No",0;
                if(lev[b[i]-1]!=lev[b[i-1]-1])
                    zz=1;
            }
        }
    }
    cout<<"Yes";
}


//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n+1);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No"<<i,0;
                else vis[par[b[i]-1]]=1;
            }
        }
    }
    cout<<"Yes";
}


//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[b[i]]&&vis[b[i-1]]&&vis[b[i]]<vis[b[i-1]-1])
                    return cout<<"No",0;
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
            }
        }
    }
    cout<<"Yes";
}


//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n+1);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=1;
            }
        }
    }
    cout<<"Yes";
}


// I should have read the announcement.

//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    //if(b[0]!=1)
        //return cout<<"No",0;
    //else
    {
        dfs(b[0]-1,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        bool zz=0;
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
                //cout<<par<<'\n';
                //cout<<'*'<<lev<<'\n';
                //cout<<vis<<i<<'\n';
                /*if(lev[b[i]-1]!=lev[b[i-1]-1]&&!vis[b[i-1]-1])
                    return cout<<"No",0;*/
            }
            if(lev[b[i]-1]!=lev[b[i-1]-1])
                zz=1;
            //cout<<'*'<<vis[b[i-1]-1]<<' '<<vis[b[i]-1]<<'\n';
            if(zz)
            if(vis[b[i-1]-1]&&vis[b[i]-1]&&vis[b[i-1]-1]>vis[b[i]-1])
                return cout<<"No",0;
        }
    }
    cout<<"Yes";
}


//#pragma GCC optimize("Ofast")
//comma seperated min
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//#include<boost/math/special_functions/binomial.hpp>
using namespace std;
//using namespace boost::math;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
    out<<'('<<p.first<<','<<p.second<<')';
    return out;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
    for(auto &x:v)
        in>>x;
    return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
    for(auto &x:v)
        out<<x<<'\n';
    return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
    for(auto x:v)
        out<<x<<' ';
    return out;
}

#define ll         long long
#define ull        unsigned long long
#define pii        pair<int,int>
#define vb         vector<bool>
#define vi         vector<int>
#define vl         vector<long long>
#define vvi        vector<vector<int>>
#define vvl        vector<vector<long long>>
#define pb         push_back
#define mp         make_pair
#define rep(i,a,b) for(register int i=a;i<b;i++)
#define all(x)     x.begin(),x.end()
#define lbnd       lower_bound
#define ubnd       upper_bound
#define acc        accumulate
#define b_c        binomial_coefficient
#define F          first
#define S          second

const long double pi=2*asin(1);

int n;
vi par,lev,vis;
vvi M;

void dfs(int x,int l,int p)
{
    vis[x]=1;
    lev[x]=l;
    par[x]=p;
    for(auto y:M[x])
    {
        if(!vis[y])
        dfs(y,l+1,x);
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    lev.resize(n);
    par.resize(n);
    M.resize(n);
    vis.resize(n);
    rep(i,0,n-1)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        M[a].pb(b);
        M[b].pb(a);
    }
    vi b(n);
    cin>>b;
    if(b[0]!=1)
        return cout<<"No",0;
    else
    {
        dfs(0,0,n);
        vis.clear();
        vis.resize(n+1);
        //cout<<lev<<'\n';
        for(int i=b.size()-1;i>0;i--)
        {
            if(lev[b[i]-1]<lev[b[i-1]-1])
                return cout<<"No",0;
        }
        //cout<<par<<'\n';
        bool zz=0;
        for(int i=b.size()-1;i>0;i--)
        {
            if(par[b[i]-1]!=par[b[i-1]-1])
            {
                //cout<<vis<<'\n';
                if(vis[par[b[i-1]-1]])
                    return cout<<"No",0;
                else vis[par[b[i]-1]]=i+1;
                //cout<<par<<'\n';
                //cout<<'*'<<lev<<'\n';
                //cout<<vis<<i<<'\n';
                /*if(lev[b[i]-1]!=lev[b[i-1]-1]&&!vis[b[i-1]-1])
                    return cout<<"No",0;*/
                if(lev[b[i]-1]!=lev[b[i-1]-1])
                    zz=1;
                if(zz)
                if(vis[b[i-1]-1]>vis[b[i]-1])
                    return cout<<"No",0;
            }
        }
    }
    cout<<"Yes";
}


/*input
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR,vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	if(a[1] != 1) return cout<<"No",0;
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](int i, int j){return ind[i] < ind[j];});
	for(deque<int> q={1};q.size();q.pop_front()){
		auto u = q[0];
		if(u!=a[++PTR]) return cout<<"No",0;
		vis[u] = 1;
		for(auto i:v[u]) if(!vis[i])
			q.push_back(i);
	}
	cout<<"Yes";
}


/*input
2
1 2
2 1
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR=1;
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](auto i, auto j){return ind[i]<ind[j];});
	for(deque<int> q = {1};q.size();q.pop_front()){
		if(q[0] != a[PTR++]) return cout<<"No",0;
		for(auto i:v[q[0]]) {
			v[i].erase(find(v[i].begin(), v[i].end(),q[0]));
			q.push_back(i);
		}
	}
	cout<<"Yes";
}


/*input
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR=1,vis[200005];
vector<int> v[200005];
bool bfs(){
	vis[1] = true;
	queue <int> q;
	for(q.push(1);!q.empty();q.pop()) {
		int i = q.front();
		if(i != a[PTR])
			return false;
		PTR++;
		vis[i] = true;
		for(int j: v[i]) {
			if(!vis[j]) {
				vis[j] = true;
				q.push(j);
			}
		}
	}
	return true;
}
bool cp(int i, int j) {
	return ind[i] < ind[j];
}
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),cp);
	// vis[1] = 1;
	// queue<int> q;
	// q.push(1);
	// for(;q.size();q.pop()){
	// 	auto u = q.front();
	// 	if(u!=a[++PTR]) return cout<<"No",0;
	// 	for(auto i:v[u]) if(!vis[i]){
	// 		q.push(i);
	// 		vis[i] = 1;
	// 	}
	// }
	cout<<(bfs()?"Yes":"No");
}


/*input
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR,vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](int i, int j){return ind[i] < ind[j];});
	vis[1] = 1;
	for(deque<int> q={1};q.size();q.pop_front()){
		auto u = q[0];
		if(u!=a[++PTR]) return cout<<"No",0;
		for(auto i:v[u]) if(!vis[i]){
			q.push_back(i);
			vis[i] = 1;
		}
	}
	cout<<"Yes";
}


/*input
2
1 2
2 1
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR=1,vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](auto i, auto j){return ind[i]<ind[j];});
	for(deque<int> q = {1};q.size();q.pop_front()){
		if(q[0]!=a[PTR++]) return cout<<"No",0;
		vis[q[0]] = 1;
		for(auto i:v[q[0]]) if(!vis[i])
			q.push_back(i);
	}
	cout<<"Yes";
}


#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR,vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](int i, int j){
		return ind[i] < ind[j];
	});
	for(deque<int> q={1};q.size();q.pop_front()){
		auto u = q[0];
		if(u!=a[++PTR]) return cout<<"No",0;
		vis[u] = 1;
		for(auto i:v[u]) if(!vis[i])
			q.push_back(i);
	}
	cout<<"Yes";
}


/*input
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR=1,vis[200005];
vector<int> v[200005];
bool bfs(){
	vis[1] = true;
	queue <int> q;
	for(q.push(1);!q.empty();q.pop()) {
		int i = q.front();
		if(i != a[PTR])
			return false;
		PTR++;
		vis[i] = true;
		for(int j: v[i]) {
			if(!vis[j]) {
				vis[j] = true;
				q.push(j);
			}
		}
	}
	return true;
}
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](int i, int j){return ind[i] < ind[j];});
	// vis[1] = 1;
	// queue<int> q;
	// q.push(1);
	// for(;q.size();q.pop()){
	// 	auto u = q.front();
	// 	if(u!=a[++PTR]) return cout<<"No",0;
	// 	for(auto i:v[u]) if(!vis[i]){
	// 		q.push(i);
	// 		vis[i] = 1;
	// 	}
	// }
	cout<<(bfs()?"Yes":"No");
}


/*input
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR,vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](int i, int j){return ind[i] < ind[j];});
	vis[1] = 1;
	queue<int> q;
	q.push(1);
	for(;q.size();q.pop()){
		auto u = q.front();
		if(u!=a[++PTR]) return cout<<"No",0;
		for(auto i:v[u]) if(!vis[i]){
			q.push(i);
			vis[i] = 1;
		}
	}
	cout<<"Yes";
}


/*input
2
1 2
2 1
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR,vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](int i, int j){return ind[i]<ind[j];});
	vis[1] = 1;
	for(deque<int> q={1};q.size();q.pop_front()){
		if(q[0]!=a[++PTR]) return cout<<"No",0;
		vis[q[0]] = 1;
		for(auto i:v[q[0]]) if(!vis[i]){
			q.push_back(i);
			vis[i] = 1;
		}
	}
	cout<<"Yes";
}


#include <bits/stdc++.h>
using namespace std;
int a[200005],lvl[200005],n,par[200005],ind[200005];
set<int> v[200005];
deque<int> ht[200005];
void dfs(int u, int dad=0, int d=1){
	lvl[u] = d, par[u] = dad;
	v[u].erase(dad);
	for(auto i:v[u]) if(i!=dad)
		dfs(i,u,d+1);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=n,x,y;--i;v[x].insert(y),v[y].insert(x))
		cin>>x>>y;
	for(int i=1;i<=n;cin>>a[i++]);
	if(a[1]!=1) return cout<<"No",0;
	dfs(a[1]);
	for(int i=2;i<=n;++i) if(lvl[a[i]]<lvl[a[i-1]])
		return cout<<"No",0;
	for(int i=1;i<=n;++i){
		ht[lvl[a[i]]].push_back(a[i]);
		ind[a[i]] = ht[lvl[a[i]]].size();
	}
	for(int i=1;i<=n;++i){
		vector<int> now;
		for(auto j:ht[i]) now.push_back(ind[par[j]]);
		if(!is_sorted(now.begin(), now.end()))
			return cout<<"No",0;
	}
	cout<<"Yes";
}


#include <bits/stdc++.h>
using namespace std;
int n,PTR,a[200005],ind[200005],vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;sort(v[i].begin(),v[i].end(),[](int i, int j){return ind[i]<ind[j];}));
	for(deque<int> q={1};q.size();q.pop_front()){
		vis[q[0]] = 1;
		if(q[0]!=a[++PTR]) return cout<<"No",0;
		for(auto i:v[q[0]]) if(!vis[i]) q.push_back(i);
	}
	cout<<"Yes";
}


/*input
2
1 2
2 1
4
1 2
1 3
2 4
1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],n,ind[200005],PTR=1,vis[200005];
vector<int> v[200005];
int main(){
	cin>>n;
	for(int i=n,x,y;--i;v[x].push_back(y),v[y].push_back(x)) cin>>x>>y;
	for(int i=0;i++<n;ind[a[i]]=i) cin>>a[i];
	for(int i=0;i++<n;++i) sort(v[i].begin(),v[i].end(),[](auto i, auto j){return ind[i]<ind[j];});
	for(deque<int> q = {1};q.size();q.pop_front()){
		if(q[0]!=a[PTR++]) return cout<<"No",0;
		vis[q[0]] = 1;
		for(auto i:v[q[0]]) if(!vis[i]){
			vis[i] = 1;
			q.push_back(i);
		}
	}
	cout<<"Yes";
}


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

vector<vector<int>> cnn;
vector<int> p, lvl;

void dfs(int u, int l) {
  lvl[u] = l;
  for (int i = 0; i < cnn[u].size(); i++) {
    int v = cnn[u][i];
    if (lvl[v] == 0) {
      dfs(v, l + 1);
      p[v] = u;
    }
  }
}

int main() {
  int n;
  cin >> n;
  cnn.resize(n);
  p.resize(n);
  lvl.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    cnn[u - 1].push_back(v - 1);
    cnn[v - 1].push_back(u - 1);
  }
  vector<int> a(n), pos(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[a[i] - 1] = i;
  }
  // get levels and parents
  p[0] = -1;
  dfs(0, 1);
  // start from vertex 1
  bool ok = a[0] == 1;
  // check levels
  vector<int> ord(lvl);
  sort(ord.begin(), ord.end());
  for (int i = 0; i < n; i++) {
    if (lvl[a[i] - 1] != ord[i]) {
      ok = false;
      break;
    }
  }
  // check order of parents
  for (int i = 1; i < n - 1; i++) {
    if (pos[p[a[i] - 1]] > pos[p[a[i + 1] - 1]]) {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> color(n, 0);
  color[0] = 1;
  bool ok = a[0] == 0;
  int i = 0, j = 1;
  while (i < j) {
    set<int> s1;
    for (int u: g[a[i]]) {
      if (!color[u]) {
        color[u] = 1;
        s1.insert(u);
      }
    }
    set<int> s2;
    for (int k = j; k < j + s1.size(); k++) {
      s2.insert(a[k]);
    }
    if (s1 != s2) {
      ok = false;
      break;
    }
    i++;
    j += s1.size();
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> cnn;
vector<int> level;

void dfs(int u, int l) {
  level[u] = l;
  for (int i = 0; i < cnn[u].size(); i++) {
    int v = cnn[u][i];
    if (level[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  cnn.resize(n);
  level.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    cnn[s - 1].push_back(t - 1);
    cnn[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0, 1);
  for (int i = 0; i < n; i++) {
    cout << level[i] << " ";
  }
  cout << "\n";
  bool valid = a[0] == 1;
  vector<int> order(level);
  sort(order.begin(), order.end());
  for (int i = 0; i < n; i++) {
    if (level[a[i] - 1] != order[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> g;
vector<int> level;

void dfs(int u, int l) {
  level[u] = l;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (level[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  g.resize(n);
  level.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    g[s - 1].push_back(t - 1);
    g[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0, 1);
  bool valid = a[0] == 1 and level[a[0]] == 1;
  for (int i = 0; i < n; i++) {
    if (level[a[i] - 1] != level[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> cnn;
vector<int> level;

void dfs(int u, int l) {
  level[u] = l;
  for (int i = 0; i < cnn[u].size(); i++) {
    int v = cnn[u][i];
    if (level[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  cnn.resize(n);
  level.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    cnn[s - 1].push_back(t - 1);
    cnn[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0, 1);
  bool valid = a[0] == 1;
  vector<int> order(level);
  sort(order.begin(), order.end());
  for (int i = 0; i < n; i++) {
    if (level[a[i] - 1] != order[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> g;
vector<int> level;

void dfs(int u, int l) {
  level[u] = l;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (level[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  g.resize(n);
  level.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    g[s - 1].push_back(t - 1);
    g[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0, 1);
  for (int i = 0; i < n; i++) {
    cout << level[i] << " ";
  }
  cout << "\n";
  bool valid = a[0] == 1 and level[a[0] - 1] == 1;
  for (int i = 0; i < n; i++) {
    if (level[a[i] - 1] != level[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> cnn;
vector<int> lvl;

void dfs(int u, int l) {
  lvl[u] = l;
  for (int i = 0; i < cnn[u].size(); i++) {
    int v = cnn[u][i];
    if (lvl[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  cnn.resize(n);
  lvl.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    cnn[u - 1].push_back(v - 1);
    cnn[v - 1].push_back(u - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0, 1);
  bool valid = a[0] == 1;
  vector<int> ord(lvl);
  sort(ord.begin(), ord.end());
  for (int i = 0; i < n; i++) {
    if (lvl[a[i] - 1] != ord[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> cnn(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    cnn[s - 1].push_back(t - 1);
    cnn[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ok = a[0] == 1;
  vector<int> color(n, 0);
  queue<int> q;
  q.push(0);
  color[0] = 1;
  int j = 1;
  while (ok and j < n) {
    int u = q.front();
    q.pop();
    set<int> A;
    set<int> B;
    for (int i = 0; i < cnn[u].size(); i++) {
      A.insert(a[j + i] - 1);
      B.insert(cnn[u][i]);
    }
    if (A != B) {
      ok = false;
      break;
    }
    for (int i = 0; i < cnn[u].size(); i++) {
      int v = a[j + i] - 1;
      if (!color[v]) {
        color[v] = 1;
        q.push(v);
      }
    }
    j += cnn[u].size();
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n), c(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    p[t - 1] = s - 1;
    c[s - 1]++;
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ok = a[0] == 1;
  bool next = false;
  int cp = 1;
  for (int i = 1; ok and i < n; i++) {
    if (p[a[i]] == cp) {
      c[cp]--;
      if (c[cp] == 0) {
        next = true;
      }
    } else {
      if (next) {
        cp = p[a[i]];
        c[cp]--;
        if (c[cp] == 0) {
          next = true;
        }
      } else {
        ok = false;
        break;
      }
    }
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> cnn;
vector<int> level;

void dfs(int u, int l) {
  level[u] = l;
  for (int i = 0; i < cnn[u].size(); i++) {
    int v = cnn[u][i];
    if (level[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  cnn.resize(n);
  level.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    cnn[s - 1].push_back(t - 1);
    cnn[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  level[0] = 1;
  dfs(0, 1);
  bool valid = true;
  for (int i = 0; i < n; i++) {
    if (level[a[i] - 1] != level[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> cnn;
vector<int> level;

void dfs(int u, int l) {
  level[u] = l;
  for (int i = 0; i < cnn[u].size(); i++) {
    int v = cnn[u][i];
    if (level[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  cnn.resize(n);
  level.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    cnn[s - 1].push_back(t - 1);
    cnn[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  level[0] = 1;
  dfs(0, 1);
  bool valid = a[0] == 1;
  for (int i = 0; i < n; i++) {
    if (level[a[i] - 1] != level[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n), c(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    p[t] = s;
    c[s]++;
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ok = a[0] == 1;
  bool next = false;
  int cp = 1;
  for (int i = 1; ok and i < n; i++) {
    if (p[a[i]] == cp) {
      c[cp]--;
      if (c[cp] == 0) {
        next = true;
      }
    } else {
      if (next) {
        cp = p[a[i]];
        c[cp]--;
        if (c[cp] == 0) {
          next = true;
        }
      } else {
        ok = false;
        break;
      }
    }
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1), c(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    p[t] = s;
    c[s]++;
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ok = a[0] == 1;
  bool next = false;
  int cp = 1;
  for (int i = 1; ok and i < n; i++) {
    if (p[a[i]] == cp) {
      c[cp]--;
      if (c[cp] == 0) {
        next = true;
      }
    } else {
      if (next) {
        cp = p[a[i]];
        c[cp]--;
        if (c[cp] == 0) {
          next = true;
        }
      } else {
        ok = false;
        break;
      }
    }
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

set<pair<int, int>> memo;

int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1), c(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    memo.insert(make_pair(s, t));
    memo.insert(make_pair(t, s));
    p[t] = s;
    c[s]++;
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool ok = a[0] == 1;
  bool next = false;
  int cp = 1;
  for (int i = 1; ok and i < n; i++) {
    if (memo.count({a[i], cp})) {
      c[cp]--;
      if (c[cp] == 0) {
        next = true;
      }
    } else {
      if (next) {
        cp = p[a[i]];
        c[cp]--;
        if (c[cp] == 0) {
          next = true;
        }
      } else {
        ok = false;
        break;
      }
    }
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

vector<vector<int>> g;
vector<int> level;

void dfs(int u, int l) {
  level[u] = l;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (level[v] == 0) {
      dfs(v, l + 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  g.resize(n);
  level.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    g[s - 1].push_back(t - 1);
    g[t - 1].push_back(s - 1);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(0, 1);
  bool valid = a[0] == 1 and level[a[0] - 1] == 1;
  for (int i = 0; i < n; i++) {
    if (level[a[i] - 1] != level[i]) {
      valid = false;
      break;
    }
  }
  if (valid) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  bool ok = a[0] == 0;
  vector<int> color(n, 0);
  color[0] = 1;
  int i = 0, j = 1;
  while (i < j) {
    set<int> s1;
    for (int u: g[i]) {
      if (!color[u]) {
        color[u] = 1;
        s1.insert(u);
      }
    }
    set<int> s2;
    for (int k = j; k < j + s1.size(); k++) {
      s2.insert(a[k]);
    }
    if (s1 != s2) {
      ok = false;
      break;
    }
    i++;
    j += s1.size();
  }
  if (ok) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v2[a].pb(b);
       v2[b].pb(a);
    }

    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
       // cout<<v[i].size()<<" ";
    }

    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];

    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll start=1,flag=0;
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];
        set<ll>x,y;

        for(k=0;k<v[l].size();k++)
        {
            if( visited[v[l][k]]==false)
            x.insert(v[l][k]);

            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+v[l].size()-1;j++)
        {
           // cout<<ar[j]<<" ";
           if(visited[ar[j]]==false)
            y.insert(ar[j]);
        }
        if(x!=y)
        {
            cout<<"No"<<endl;
            return 0;
        }
        for(auto idx:x)
        {
            visited[idx]=true;
           // cout<<idx<<endl;
        }
        start=j;

    }

    if(start!=j||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v[a].pb(b);
       v[b].pb(a);
    }
    /*
    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
       // cout<<v[i].size()<<" ";
    }
    */
    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll start=1,flag=0,size;
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];
        size=0;

        if(v[l].size()!=0)
        {
        for(k=0;k<v[l].size();k++)
        {

            if(visited[v[l][k]]==false)
            {
            visited[v[l][k]]=true;
            size++;
            }
            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+size-1;j++)
        {
           // cout<<ar[j]<<" ";
            if(visited[ar[j]]==false)
            {
                flag=1;
                break;
            }
        }
        }
        start=j;
        if(flag==1)
        break;
    }

    if(flag==1||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define INF LONG_MAX
ll dist[100005];
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll i;
    dist[r]=0;
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                dist[v[u][i]]=dist[u]+1;

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b;
    ll ar[n];
    vector<ll>v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v[a].pb(b);
    }
    findans(v,n,1);
    for(i=0;i<n;i++)
    {
       //cout<<dist[i+1]<<endl;
        cin>>ar[i];
    }
    for(i=0;i<n-1;i++)
    {
        if(dist[ar[i+1]]<dist[ar[i]])
            break;
    }
    if(i!=n-1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v2[a].pb(b);
       v2[b].pb(a);
    }
    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
       // cout<<v[i].size()<<" ";
    }

    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll start=1,flag=0;,size
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];
        size=0;

        if(v[l].size()!=0)
        {
        for(k=0;k<v[l].size();k++)
        {

            if(visited[v[l][k]]==false)
            {
            visited[v[l][k]]=true;
            size++;
            }
            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+size-1;j++)
        {
           // cout<<ar[j]<<" ";
            if(visited[ar[j]]==false)
            {
                flag=1;
                break;
            }
        }
        }
        start=j;
        if(flag==1)
        break;
    }

    if(flag==1||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v[a].pb(b);
       v[b].pb(a);
    }
    /*
    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
       // cout<<v[i].size()<<" ";
    }
    */
    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];

    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    if(n==1)
    {
        cout<<"Yes";
        return 0;
    }
    ll start=1,flag=0;
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];
        set<ll>x,y;

        for(k=0;k<v[l].size();k++)
        {
            if( visited[v[l][k]]==false)
            x.insert(v[l][k]);

            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+x.size()-1;j++)
        {
           // cout<<ar[j]<<" ";
           if(visited[ar[j]]==false)
            y.insert(ar[j]);
        }
        if(x!=y)
        {
            cout<<"No"<<endl;
            return 0;
        }
        for(auto idx:x)
        {
            visited[idx]=true;
           // cout<<idx<<endl;
        }
        start=j;

    }

    if(start!=j||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define INF LONG_MAX
ll dist[100005];
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll i;
    dist[r]=0;
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                dist[v[u][i]]=dist[u]+1;

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b;
    ll ar[n];
    vector<ll>v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v[a].pb(b);
    }
    findans(v,n,1);
    for(i=0;i<n;i++)
    {
       // cout<<dist[i+1]<<endl;
        cin>>ar[i];
    }
    for(i=0;i<n-1;i++)
    {
        if(dist[ar[i+1]]>=dist[ar[i]])
            continue;
        else
            break;
    }
    if(i==n-1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v2[a].pb(b);
       v2[b].pb(a);
    }
    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
       // cout<<v[i].size()<<" ";
    }

    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll start=1,flag=0;
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];

        if(v[l].size()!=0)
        {
        for(k=0;k<v[l].size();k++)
        {
            visited[v[l][k]]=true;
            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+v[l].size()-1;j++)
        {
           // cout<<ar[j]<<" ";
            if(visited[ar[j]]==false)
            {
                flag=1;
                break;
            }
        }
        }
        start=j;
        if(flag==1)
        break;
    }

    if(flag==1||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v2[a].pb(b);
       v2[b].pb(a);
    }
    /*
    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
       // cout<<v[i].size()<<" ";
    }
    */
    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];

    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll start=1,flag=0;
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];
        set<ll>x,y;

        for(k=0;k<v[l].size();k++)
        {
            if( visited[v[l][k]]==false)
            x.insert(v[l][k]);

            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+v[l].size()-1;j++)
        {
           // cout<<ar[j]<<" ";
            y.insert(ar[j]);
        }
        if(x!=y)
        {
            cout<<"No"<<endl;
            return 0;
        }
        for(auto idx:x)
        {
            visited[idx]=true;
        }
        start=j;

    }

    if(start!=j||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v2[a].pb(b);
       v2[b].pb(a);
    }
    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
    }

    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll start=1,flag=0;
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];

        for(k=0;k<v[l].size();k++)
        {
            visited[v[l][k]]=true;
            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+v[l].size()-1;j++)
        {
           // cout<<ar[j]<<" ";
            if(visited[ar[j]]==false)
            {
                flag=1;
                break;
            }
        }
        start=j;
        if(flag==1)
        break;
    }

    if(flag==1||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll>v1;
void findans(vector<ll>v[],ll n,ll r)
{
    bool visited[n];
    memset(visited,false,sizeof(visited));
    queue<ll>q;
    q.push(r);
    visited[r]=true;
    ll ans=1,i;
    v1.pb(r);
    while(q.empty()!=true)
    {

        ll u=q.front();
        q.pop();
        visited[u]=true;
        for(i=0;i<v[u].size();i++)
        {
            if(visited[v[u][i]]==false)
            {
                q.push(v[u][i]);
                v1.pb(v[u][i]);

            }
        }

    }
    }

main()
{
    ll n,m;
    cin>>n;
    ll i,a,b,j;
    vector<ll>v2[n+1],v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v2[a].pb(b);
       v2[b].pb(a);
    }

    ll pos[n+1];
    findans(v2,n,1);
    for(i=0;i<v1.size();i++)
    {
        //cout<<v1[i]<<" "<<endl;
        pos[v1[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        for(j=0;j<v2[i].size();j++)
        {
            if(pos[v2[i][j]]>pos[i])
            v[i].pb(v2[i][j]);
        }
       // cout<<v[i].size()<<" ";
    }

    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll k;
    ll ar[n+1];

    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    if(n==1)
    {
        cout<<"Yes";
        return 0;
    }
    ll start=1,flag=0;
    visited[1]=true;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];
        set<ll>x,y;

        for(k=0;k<v[l].size();k++)
        {
            if( visited[v[l][k]]==false)
            x.insert(v[l][k]);

            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+v[l].size()-1;j++)
        {
           // cout<<ar[j]<<" ";
           if(visited[ar[j]]==false)
            y.insert(ar[j]);
        }
        if(x!=y)
        {
            cout<<"No"<<endl;
            return 0;
        }
        for(auto idx:x)
        {
            visited[idx]=true;
           // cout<<idx<<endl;
        }
        start=j;

    }

    if(start!=j||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
main()
{
    ll n,m;
    cin>>n;
    ll i,a,b;
    vector<ll>v[n+1];
    for(i=0;i<n-1;i++)
    {
       cin>>a>>b;
       v[a].pb(b);
    }
    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    ll j,k;
    ll ar[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll start=1,flag=0;
    for(i=0;i<n&&start<n;i++)
    {
        ll l=ar[i];

        for(k=0;k<v[l].size();k++)
        {
            visited[v[l][k]]=true;
            //cout<<v[l][k]<<" ";
        }

        for(j=start;j<=start+v[l].size()-1;j++)
        {
            //cout<<ar[j]<<" ";
            if(visited[ar[j]]==false)
            {
                flag=1;
                break;
            }
        }
        start=j;
        if(flag==1)
        break;
    }

    if(flag==1||ar[0]!=1)
    cout<<"No";
    else
    cout<<"Yes";

}