#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef double db;

#define mp make_pair
#define pb push_back
#define pt(i) printf("%lld\n",(ll)i)
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1.0)

ll in() { ll a;scanf("%lld",&a); return a;}
db din(){ db a;scanf("%lf",&a); return a; }
ll bigmod(ll b, ll p,ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}

vi node[200005];
int dis[200005],ar[200005],par[200005];

void bfs(int s)
{
    dis[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<node[u].size();i++)
        {
            int v=node[u][i];
            if(dis[v]==-1)
            {
                par[v]=u;
                dis[v]=1+dis[u];
                q.push(v);
            }
        }
    }
}

int main()
{
    memset(dis,-1,sizeof dis);
    int n=in();
    for(int i=0;i<n-1;i++)
    {
        int a=in(),b=in();
        node[a].pb(b);
        node[b].pb(a);
    }
    bfs(1);
    bool hobe=1;
    int pos=1;
    for(int i=0;i<n;i++)
    {
        ar[i]=in();
        if(i)
        {
            while(pos<i&&ar[pos-1]!=par[ar[i]])
                pos++;
            if(i>1){
            if(pos==i)
                hobe=0;}
            else if(par[ar[i]]!=1)
                hobe=0;
        }
    }
    if(hobe)
        puts("Yes");
    else
        puts("No");
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef double db;

#define mp make_pair
#define pb push_back
#define pt(i) printf("%lld\n",(ll)i)
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1.0)

ll in() { ll a;scanf("%lld",&a); return a;}
db din(){ db a;scanf("%lf",&a); return a; }
ll bigmod(ll b, ll p,ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}

vi node[200005];
int dis[200005],ar[200005],par[200005];

void bfs(int s)
{
    dis[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<node[u].size();i++)
        {
            int v=node[u][i];
            if(dis[v]==-1)
            {
                par[v]=u;
                dis[v]=1+dis[u];
                q.push(v);
            }
        }
    }
}

int main()
{
    memset(dis,-1,sizeof dis);
    int n=in();
    for(int i=0;i<n-1;i++)
    {
        int a=in(),b=in();
        node[a].pb(b);
        node[b].pb(a);
    }
    bfs(1);
    bool hobe=1;
    int pos=0;
    for(int i=0;i<n;i++)
    {
        ar[i]=in();
        if(i)
        {
            if(dis[ar[i]]<dis[ar[i-1]])
                hobe=0;
            if(ar[pos-1]==par[ar[i]]);
            else if(ar[pos]==par[ar[i]])
                pos++;
            else
                hobe=0;
        }
    }
    if(hobe)
        puts("Yes");
    else
        puts("No");
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef double db;

#define mp make_pair
#define pb push_back
#define pt(i) printf("%lld\n",(ll)i)
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1.0)

ll in() { ll a;scanf("%lld",&a); return a;}
db din(){ db a;scanf("%lf",&a); return a; }
ll bigmod(ll b, ll p,ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}

vi node[200005];
int dis[200005],ar[200005],par[200005];

void bfs(int s)
{
    dis[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<node[u].size();i++)
        {
            int v=node[u][i];
            if(dis[v]==-1)
            {
                par[v]=u;
                dis[v]=1+dis[u];
                q.push(v);
            }
        }
    }
}

int main()
{
    memset(dis,-1,sizeof dis);
    int n=in();
    for(int i=0;i<n-1;i++)
    {
        int a=in(),b=in();
        node[a].pb(b);
        node[b].pb(a);
    }
    bfs(1);
    bool hobe=1;
    int pos=1;
    for(int i=0;i<n;i++)
    {
        ar[i]=in();
        if(i)
        {
            while(pos<i&&ar[pos-1]!=par[ar[i]])
                pos++;
            if(i>1)
            if(pos==i)
                hobe=0;
            else if(par[ar[i]]!=1)
                hobe=0;
        }
    }
    if(hobe)
        puts("Yes");
    else
        puts("No");
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef double db;

#define mp make_pair
#define pb push_back
#define pt(i) printf("%lld\n",(ll)i)
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1.0)

ll in() { ll a;scanf("%lld",&a); return a;}
db din(){ db a;scanf("%lf",&a); return a; }
ll bigmod(ll b, ll p,ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}

vi node[200005];
int dis[200005],ar[200005],par[200005];

void bfs(int s)
{
    dis[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<node[u].size();i++)
        {
            int v=node[u][i];
            if(dis[v]==-1)
            {
                par[v]=u;
                dis[v]=1+dis[u];
                q.push(v);
            }
        }
    }
}

int main()
{
    memset(dis,-1,sizeof dis);
    int n=in();
    for(int i=0;i<n-1;i++)
    {
        int a=in(),b=in();
        node[a].pb(b);
        node[b].pb(a);
    }
    bfs(1);
    bool hobe=1;
    int pos=1;
    for(int i=0;i<n;i++)
    {
        ar[i]=in();
        if(i)
        {
            if(dis[ar[i]]<dis[ar[i-1]])
                hobe=0;
            if(ar[pos-1]==par[ar[i]]);
            else if(ar[pos]==par[ar[i]])
                pos++;
            else
                hobe=0;
        }
    }
    if(hobe)
        puts("Yes");
    else
        puts("No");
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef double db;

#define mp make_pair
#define pb push_back
#define pt(i) printf("%lld\n",(ll)i)
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1.0)

ll in() { ll a;scanf("%lld",&a); return a;}
db din(){ db a;scanf("%lf",&a); return a; }
ll bigmod(ll b, ll p,ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}

vi node[200005];
int dis[200005],ar[200005],par[200005];

void bfs(int s)
{
    dis[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<node[u].size();i++)
        {
            int v=node[u][i];
            if(dis[v]==-1)
            {
                par[v]=u;
                dis[v]=1+dis[u];
                q.push(v);
            }
        }
    }
}

int main()
{
    memset(dis,-1,sizeof dis);
    int n=in();
    for(int i=0;i<n-1;i++)
    {
        int a=in(),b=in();
        node[a].pb(b);
        node[b].pb(a);
    }
    bfs(1);
    bool hobe=1;
    int pos=1;
    for(int i=0;i<n;i++)
    {
        ar[i]=in();
        if(dis[ar[i]]==-1)
            hobe=0;
        else if(i)
        {
            while(pos<=i&&ar[pos-1]!=par[ar[i]])
                pos++;
            if(i>1){
            if(pos==i)
                hobe=0;}
            else if(par[ar[i]]!=1)
                hobe=0;
        }
    }
    if(hobe)
        puts("Yes");
    else
        puts("No");
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef double db;

#define mp make_pair
#define pb push_back
#define pt(i) printf("%lld\n",(ll)i)
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1.0)

ll in() { ll a;scanf("%lld",&a); return a;}
db din(){ db a;scanf("%lf",&a); return a; }
ll bigmod(ll b, ll p,ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}

vi node[200005];
int dis[200005];

void bfs(int s)
{
    dis[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<node[u].size();i++)
        {
            int v=node[u][i];
            if(dis[v]==-1)
            {
                dis[v]=1+dis[u];
                q.push(v);
            }
        }
    }
}

int main()
{
    memset(dis,-1,sizeof dis);
    int n=in();
    for(int i=0;i<n-1;i++)
    {
        int a=in(),b=in();
        node[a].pb(b);
        node[b].pb(a);
    }
    int ar[n+5];
    bfs(1);
    bool hobe=1;
    for(int i=0;i<n;i++)
    {
        ar[i]=in();
        if(i)
        {
            if(dis[ar[i]]<dis[ar[i-1]])
                hobe=0;
        }
    }
    if(hobe)
        puts("Yes");
    else
        puts("No");
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef double db;

#define mp make_pair
#define pb push_back
#define pt(i) printf("%lld\n",(ll)i)
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1.0)

ll in() { ll a;scanf("%lld",&a); return a;}
db din(){ db a;scanf("%lf",&a); return a; }
ll bigmod(ll b, ll p,ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}

vi node[200005];
int dis[200005],ar[200005],par[200005];

void bfs(int s)
{
    dis[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=0;i<node[u].size();i++)
        {
            int v=node[u][i];
            if(dis[v]==-1)
            {
                par[v]=u;
                dis[v]=1+dis[u];
                q.push(v);
            }
        }
    }
}

int main()
{
    memset(dis,-1,sizeof dis);
    int n=in();
    for(int i=0;i<n-1;i++)
    {
        int a=in(),b=in();
        node[a].pb(b);
        node[b].pb(a);
    }
    bfs(1);
    bool hobe=1;
    int pos=1;
    for(int i=0;i<n;i++)
    {
        ar[i]=in();
        if(dis[ar[i]]==-1)
            hobe=0;
        else if(i)
        {
            while(pos<i&&ar[pos-1]!=par[ar[i]])
                pos++;
            if(i>1){
            if(pos==i)
                hobe=0;}
            else if(par[ar[i]]!=1)
                hobe=0;
        }
    }
    if(hobe)
        puts("Yes");
    else
        puts("No");
}


#include <bits/stdc++.h>

using namespace std;

typedef vector< int > vector_t;

vector< vector_t > g; vector_t h; vector< bool > used;

bool compare_order( int x, int y )
{
    return h[ x ] < h[ y ];
}

struct queue_t: queue< int >
{
    queue_t()
    {
        push( 0 ), used.front() = true;
    }

    bool ordered( int u, int &v )
    {
        return not empty() and ( u == ( v = front() ) );
    }
};

struct ordered_neighbors: vector_t
{
    ordered_neighbors( int v )
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( u ), used[ u ] = true;

        sort( begin(), end(), compare_order );
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, g.resize( n ), h.resize( n ), used.resize( n ); int a[ n ];

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i, used[ i ] = false;

    queue_t q; const string ans[] = { "No", "Yes" };

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        for( auto u: ordered_neighbors( v ) )
            q.push( u );

    cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

const size_t N = 2e5; int a[ N ], h[ N ], n, v, x, y; typedef vector< int > vector_t; vector_t g[ N ]; queue< int > q;

bool compare_order( int x, int y ) { return h[ x ] > h[ y ]; }

struct ordered_neighbors_t: vector_t
{
    bitset< N > used;

    void mark_and_sort_unused()
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( u ), used.set( u );

        for( sort( begin(), end(), compare_order ); not empty(); pop_back() )
            q.push( back() );
    }
} z;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr ), cin >> n, q.push( 0 ), z.used.set( 0 );

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i;

    for( int i = 0; not q.empty() and a[ i ] == ( v = q.front() ); i++, q.pop() )
        z.mark_and_sort_unused();

    const string ans[] = { "No", "Yes" }; cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

typedef vector< int > vector_t;

vector< vector_t > g; vector_t h; vector< bool > used;

struct queue_t: queue< int > { bool ordered( int u, int &v ) { return not empty() and ( u == ( v = front() ) ); } };

bool compare_order( int x, int y ) { return h[ x ] < h[ y ]; }

struct ordered_neighbors: vector_t
{
    ordered_neighbors( int v )
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( u );

        sort( begin(), end(), compare_order );
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, g.resize( n ), h.resize( n ), used.resize( n ); int a[ n ];

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i, used[ i ] = false;

    queue_t q; const string ans[] = { "No", "Yes" }; q.push( 0 ), used[ 0 ] = true;

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        for( auto u: ordered_neighbors( v ) )
            q.push( u ), used[ u ] = true;

    cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

struct queue_t: queue< int >
{
    bool ordered( int u, int &v )
    {
        return not empty() and ( u == ( v = front() ) );
    }
};

typedef vector< int > vector_t; vector_t h; bool compare_order( int x, int y ) { return h[ x ] > h[ y ]; }

struct ordered_neighbors_t: vector_t
{
    static size_t constexpr N = 2e5; bitset< N > used;

    void mark_and_sort_unused( const vector_t &w, queue_t& q )
    {
        for( auto u: w )
            if ( not used[ u ] )
                push_back( u ), used.set( u );

        for( sort( begin(), end(), compare_order ); not empty(); pop_back() )
            q.push( back() );
    }

} ordered_neighbors;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, h.resize( n ); int a[ n ]; vector< vector_t > g( n );

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i;

    queue_t q; q.push( 0 ), ordered_neighbors.used.set( 0 );

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        ordered_neighbors.mark_and_sort_unused( g[ v ], q );

    const string ans[] = { "No", "Yes" }; cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

typedef vector< int > vector_t;

struct queue_t: queue< int > { queue_t() { push( 0 ); } };

const size_t N = 200000; int h[ N ];

bool compare_order( int x, int y ) { return h[ x ] > h[ y ]; }

struct ordered_neighbors_t: vector_t
{
    bitset< N > used; ordered_neighbors_t() { used.set( 0 ); }

    void mark_and_sort_unused( const vector_t& g, queue_t& q )
    {
        for( auto u: g )
            if ( not used[ u ] )
                emplace_back( u ), used.set( u );

        for( sort( begin(), end(), compare_order ); not empty(); pop_back() )
            q.push( back() );
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n; ordered_neighbors_t z; queue_t q; cin >> n; vector_t a( n ); vector< vector_t > G( n );

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

    for( int v, i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i;

    for( int v, i = 0; not q.empty() and a[ i ] == ( v = q.front() ); i++, q.pop() )
        z.mark_and_sort_unused( G[ v ], q );

    const string ans[] = { "No", "Yes" }; cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

typedef vector< int > vector_t;

vector< vector_t > g; vector_t h;

struct queue_t: queue< int >
{
    bool ordered( int u, int &v )
    {
        return not empty() and ( u == ( v = front() ) );
    }
};

bool compare_order( int x, int y ) { return h[ x ] > h[ y ]; }

struct ordered_neighbors_t: vector_t
{
    vector< bool > used;

    void mark_and_sort_unused( int v, queue_t& q )
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( u ), used[ u ] = true;

        for( sort( begin(), end(), compare_order ); not empty(); pop_back() )
            q.push( back() );
    }

} ordered_neighbors;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, g.resize( n ), h.resize( n ), ordered_neighbors.used.resize( n ); int a[ n ];

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i, ordered_neighbors.used[ i ] = false;

    queue_t q; const string ans[] = { "No", "Yes" }; q.push( 0 ), ordered_neighbors.used[ 0 ] = true;

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        ordered_neighbors.mark_and_sort_unused( v, q );

    cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

vector< vector< int > > g; vector< int > h; vector< bool > used;

struct queue_t: queue< int >
{
    queue_t()
    {
        push( 0 ), used.front() = true;
    }

    bool ordered( int u, int &v )
    {
        return not empty() and ( u == ( v = front() ) );
    }
};

struct ordered_neighbors: vector< pair< int, int > >
{
    ordered_neighbors( int v )
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( h[ u ], u ), used[ u ] = true;

        sort( begin(), end() );
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, g.resize( n ), h.resize( n ), used.resize( n ); int a[ n ];

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = v ] = i, used[ i ] = false;

    queue_t q; const string ans[] = { "No", "Yes" };

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        for( auto p: ordered_neighbors( v ) )
            q.push( p.second );

    cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

const int N = 200001;

int a[ N ], h[ N ], v; bitset< N > used; vector< int > g[ N ];

struct queue_t: queue< int >
{
    queue_t() { push( 1 ), used.set( 1 ); }

    bool ordered( int i ) { return not empty() and ( a[ i ] == ( v = front() ) ); }
};

struct ordered_neighbors: vector< pair< int, int > >
{
    ordered_neighbors()
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( h[ u ], u ), used.set( u );

        sort( begin(), end() );
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, x, y; cin >> n; string ans[] = { "No", "Yes" }; queue_t q;

    for( int i = 1; i < n; i++ )
        cin >> x >> y, g[ x ].push_back( y ),  g[ y ].push_back( x );

    for( int i = 1; i <= n; i++ )
        cin >> v, h[ a[ i ] = v ] = i;

    for( int i = 1; q.ordered( i ); i++, q.pop() )
        for( auto p: ordered_neighbors() )
            q.push( p.second );

    cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

vector< vector< int > > g; vector< int > h; vector< bool > used;

struct queue_t: queue< int >
{
    queue_t()
    {
        push( 0 ), used.front() = true;
    }

    bool ordered( int u, int &v )
    {
        return not empty() and ( u == ( v = front() ) );
    }
};

struct ordered_neighbors: vector< pair< int, int > >
{
    ordered_neighbors( int v )
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( h[ u ], u ), used[ u ] = true;

        sort( begin(), end() );
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, g.resize( n ), h.resize( n ), used.resize( n ); int a[ n ];

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i, used[ i ] = false;

    queue_t q; const string ans[] = { "No", "Yes" };

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        for( auto p: ordered_neighbors( v ) )
            q.push( p.second );

    cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

const int N = 200001;

vector< int > g[ N ]; int a[ N ], h[ N ]; queue< int > q; bool used[ N ];

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, x, y, z = 1; cin >> n;

    for( int i = 1; i < n; i++ )
        cin >> x >> y,
        g[ x ].push_back( y ),
        g[ y ].push_back( x );

    for( int i = 1; i <= n; i++ )
        cin >> x, h[ a[ i ] = x ] = i;

    for( q.push( 1 ), used[ 1 ] = true; not q.empty(); q.pop(), z++ )
    {
        if ( ( x = q.front() ) !=  a[ z ] )
        {
            cout << "No"; return 0;
        }

        vector< pair< int, int > > f;

        for( int i = 0, m = g[ x ].size(); i < m; i++ )
            if ( not used[ y = g[ x ][ i ] ] )
                f.emplace_back( h[ y ], y ), used[ y ] = true;

        sort( f.begin(), f.end() );

        for( auto p: f )
            q.push( y = p.second );
    }

    cout << "Yes";
}


#include <bits/stdc++.h>

using namespace std;

typedef vector< int > vector_t;

vector< vector_t > g; vector_t h;

struct queue_t: queue< int >
{
    bool ordered( int u, int &v )
    {
        return not empty() and ( u == ( v = front() ) );
    }
};

bool compare_order( int x, int y ) { return h[ x ] > h[ y ]; }

struct ordered_neighbors_t: vector_t
{
    bitset< 200001 > used;

    void mark_and_sort_unused( int v, queue_t& q )
    {
        for( auto u: g[ v ] )
            if ( not used[ u ] )
                emplace_back( u ), used.set( u );

        for( sort( begin(), end(), compare_order ); not empty(); pop_back() )
            q.push( back() );
    }

} ordered_neighbors;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, g.resize( n ), h.resize( n ); int a[ n ];

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

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i;

    queue_t q; const string ans[] = { "No", "Yes" }; q.push( 0 ), ordered_neighbors.used.set( 0 );

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        ordered_neighbors.mark_and_sort_unused( v, q );

    cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>

using namespace std;

struct queue_t: queue< int >
{
    bool ordered( int u, int &v )
    {
        return not empty() and ( u == ( v = front() ) );
    }
};

typedef vector< int > vector_t; vector_t h; bool compare_order( int x, int y ) { return h[ x ] > h[ y ]; }

struct ordered_neighbors_t: vector_t
{
    bitset< 200000 > used;

    void mark_and_sort_unused( const vector_t &w, queue_t& q )
    {
        for( auto u: w )
            if ( not used[ u ] )
                emplace_back( u ), used.set( u );

        for( sort( begin(), end(), compare_order ); not empty(); pop_back() )
            q.push( back() );
    }

} ordered_neighbors;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int n, v, x, y; cin >> n, h.resize( n ); int a[ n ]; vector< vector_t > g( n );

    for( int i = 1; i < n; i++ )
        cin >> x >> y, g[ --x ].emplace_back( --y ), g[ y ].emplace_back( x );

    for( int i = 0; i < n; i++ )
        cin >> v, h[ a[ i ] = --v ] = i;

    queue_t q; q.push( 0 ), ordered_neighbors.used.set( 0 );

    for( int i = 0; q.ordered( a[ i ], v ); i++, q.pop() )
        ordered_neighbors.mark_and_sort_unused( g[ v ], q );

    const string ans[] = { "No", "Yes" }; cout << ans[ q.empty() ];
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
    int n; cin>>n;
    int a[n+1],res[n+1];
    for (int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    res[0]=a[0]=0;
    for (int i=0;i<n;i++) cin>>a[i+1];
    queue<int> q;
    q.push(1);
    int i=1;
    while (!q.empty()){
        int u=q.front();
        q.pop();
        res[i++]=u;
        vis[u]=true;
        for (auto &it: v[u]){
            if (!vis[it]){
                q.push(it);
            }
        }
    }
    int tra[18]; tra[0]=0;
    for (int i=1;i<17;i++) tra[i]=pow(2,i-1);

    for (int i=1;i<16;i++){
        if (tra[i]>n) break;
        sort(a+tra[i],a+min(n+1,tra[i+1]));
        sort(res+tra[i],res+min(tra[i+1],n+1));
    }
    bool flag=true;
    for (int i=0;i<=n;i++) {
        if (res[i] != a[i]) {
            flag=false;
            break;
        }
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
	int n,cc=0; cin>>n;
	vector <int> a(n),res(n);
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
                if (a==1 || b==1) cc++;
	}
        if (cc==n-2){
            cout<<"YES"<<endl;
            return 0;
        }
	for (int i=0;i<n;i++) cin>>a[i];
	queue<int> q;
	q.push(1);
	int i=1,c=0;
	bool flag=true;
	while (!q.empty()){
		int u=q.front();
		res[c++]=u;
		q.pop();
		vis[u]=true;
		int k=0;
		for (int j=0;j<v[u].size();j++){
			for (auto it: v[u]){
				if (it==a[i] && vis[it]==false){
					q.push(a[i]);
					i++; k++;
				}
				if (k==v[u].size()){
					break;
				}
			}
			if (k==v[u].size()){
				break;
			}
		}
	}
	for (int i=0;i<n;i++) {
		if (a[i] != res[i]) {
			flag=false;
			break;
		}
	}
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}
/*
7
1 2
1 5
2 3
2 4
5 6
5 7
1 5 2 6 7 3 4
no
*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
    int n,cc=0; cin>>n;
    vector <int> a(n),res(n);
    for (int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
        if (a==1 ) cc++;
    }
    for (int i=0;i<n;i++) cin>>a[i];
    if (a[0]!=1){
        cout<<"no"<<endl;
        return 0;
    }
    if (cc==n-1){
        cout<<"YES"<<endl;
        return 0;
    }
    queue<int> q;
    q.push(1);
    int i=1,c=0;
    bool flag=true;
    while (!q.empty()){
        int u=q.front();
        res[c++]=u;
        q.pop();
        vis[u]=true;
        int k=0;
        for (int j=0;j<v[u].size();j++){
            for (auto it: v[u]){
                if (it==a[i] && vis[it]==false){
                    q.push(a[i]);
                    i++; k++;
                }
                if (k==v[u].size()){
                    break;
                }
            }
            if (k==v[u].size()){
                break;
            }
        }
    }
    for (int i=0;i<n;i++) {
        if (a[i] != res[i]) {
            flag=false;
            break;
        }
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
	int n,cc=0; cin>>n;
	vector <int> a(n),res(n);
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	for (int i=0;i<n;i++) cin>>a[i];
	queue<int> q;
	q.push(1);
	int i=1,c=0;
	bool flag=true;
	while (!q.empty()){
		int u=q.front();
		res[c++]=u;
		q.pop();
		vis[u]=true;
		int k=0;
		for (int j=0;j<v[u].size();j++){
			for (auto it: v[u]){
				if (it==a[i] && vis[it]==false){
					q.push(a[i]);
					i++; k++;
				}
				if (k==v[u].size()){
					break;
				}
			}
			if (k==v[u].size()){
				break;
			}
		}
	}
	for (int i=0;i<n;i++) {
		if (a[i] != res[i]) {
			flag=false;
			break;
		}
	}
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}
/*
7
1 2
1 5
2 3
2 4
5 6
5 7
1 5 2 6 7 3 4
no
*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
	int n,f=0; cin>>n;
	vector <int> a(n),res(n);
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
                if (a!=1) f=1;
	}
        if (f==0) {
            cout<<"YES"<<endl;
            return 0;
        }
	for (int i=0;i<n;i++) cin>>a[i];
	queue<int> q;
	q.push(1);
	int i=1,c=0;
	bool flag=true;
	while (!q.empty()){
		int u=q.front();
		res[c++]=u;
		q.pop();
		vis[u]=true;
		int k=0;
		for (int j=0;j<v[u].size();j++){
			for (auto it: v[u]){
				if (it==a[i] && vis[it]==false){
					q.push(a[i]);
					i++; k++;
				}
				if (k==v[u].size()){
					break;
				}
			}
			if (k==v[u].size()){
				break;
			}
		}
	}
	for (int i=0;i<n;i++) {
		if (a[i] != res[i]) {
			flag=false;
			break;
		}
	}
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}
/*
7
1 2
1 5
2 3
2 4
5 6
5 7
1 5 2 6 7 3 4
no
*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
    int n,cc=0; cin>>n;
    vector <int> a(n),res(n);
    for (int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
        if (a==1 ) cc++;
    }
    for (int i=0;i<n;i++) cin>>a[i];
    if (cc==n-1){
        cout<<"YES"<<endl;
        return 0;
    }
    queue<int> q;
    q.push(1);
    int i=1,c=0;
    bool flag=true;
    while (!q.empty()){
        int u=q.front();
        res[c++]=u;
        q.pop();
        vis[u]=true;
        int k=0;
        for (int j=0;j<v[u].size();j++){
            for (auto it: v[u]){
                if (it==a[i] && vis[it]==false){
                    q.push(a[i]);
                    i++; k++;
                }
                if (k==v[u].size()){
                    break;
                }
            }
            if (k==v[u].size()){
                break;
            }
        }
    }
    for (int i=0;i<n;i++) {
        if (a[i] != res[i]) {
            flag=false;
            break;
        }
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
	int n,cc=0; cin>>n;
	vector <int> a(n),res(n);
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
                if (a==1 || b==1) cc++;
	}
        if (cc==n-1){
            cout<<"YES"<<endl;
            return 0;
        }
	for (int i=0;i<n;i++) cin>>a[i];
	queue<int> q;
	q.push(1);
	int i=1,c=0;
	bool flag=true;
	while (!q.empty()){
		int u=q.front();
		res[c++]=u;
		q.pop();
		vis[u]=true;
		int k=0;
		for (int j=0;j<v[u].size();j++){
			for (auto it: v[u]){
				if (it==a[i] && vis[it]==false){
					q.push(a[i]);
					i++; k++;
				}
				if (k==v[u].size()){
					break;
				}
			}
			if (k==v[u].size()){
				break;
			}
		}
	}
	for (int i=0;i<n;i++) {
		if (a[i] != res[i]) {
			flag=false;
			break;
		}
	}
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}
/*
7
1 2
1 5
2 3
2 4
5 6
5 7
1 5 2 6 7 3 4
no
*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
    int n,cc=0; cin>>n;
    vector <int> a(n),res(n);
    for (int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
        if (a==1 || b==1) cc++;
    }
    for (int i=0;i<n;i++) cin>>a[i];
    if (cc==n-1){
        cout<<"YES"<<endl;
        return 0;
    }
    queue<int> q;
    q.push(1);
    int i=1,c=0;
    bool flag=true;
    while (!q.empty()){
        int u=q.front();
        res[c++]=u;
        q.pop();
        vis[u]=true;
        int k=0;
        for (int j=0;j<v[u].size();j++){
            for (auto it: v[u]){
                if (it==a[i] && vis[it]==false){
                    q.push(a[i]);
                    i++; k++;
                }
                if (k==v[u].size()){
                    break;
                }
            }
            if (k==v[u].size()){
                break;
            }
        }
    }
    for (int i=0;i<n;i++) {
        if (a[i] != res[i]) {
            flag=false;
            break;
        }
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
	int n,f=0; cin>>n;
	vector <int> a(n),res(n);
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
                if (a!=1) f=1;
	}
	for (int i=0;i<n;i++) cin>>a[i];
	queue<int> q;
        if (f==0) {
            cout<<"YES"<<endl;
            return 0;
        }
	q.push(1);
	int i=1,c=0;
	bool flag=true;
	while (!q.empty()){
		int u=q.front();
		res[c++]=u;
		q.pop();
		vis[u]=true;
		int k=0;
		for (int j=0;j<v[u].size();j++){
			for (auto it: v[u]){
				if (it==a[i] && vis[it]==false){
					q.push(a[i]);
					i++; k++;
				}
				if (k==v[u].size()){
					break;
				}
			}
			if (k==v[u].size()){
				break;
			}
		}
	}
	for (int i=0;i<n;i++) {
		if (a[i] != res[i]) {
			flag=false;
			break;
		}
	}
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}
/*
7
1 2
1 5
2 3
2 4
5 6
5 7
1 5 2 6 7 3 4
no
*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool vis[200010];
vector<int> v[200010];
int main(){
	int n,f=0; cin>>n;
	vector <int> a(n),res(n);
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
                if (a!=1) f=1;
	}
        if (f==0) {
            cout<<"NO"<<endl;
            return 0;
        }
	for (int i=0;i<n;i++) cin>>a[i];
	queue<int> q;
	q.push(1);
	int i=1,c=0;
	bool flag=true;
	while (!q.empty()){
		int u=q.front();
		res[c++]=u;
		q.pop();
		vis[u]=true;
		int k=0;
		for (int j=0;j<v[u].size();j++){
			for (auto it: v[u]){
				if (it==a[i] && vis[it]==false){
					q.push(a[i]);
					i++; k++;
				}
				if (k==v[u].size()){
					break;
				}
			}
			if (k==v[u].size()){
				break;
			}
		}
	}
	for (int i=0;i<n;i++) {
		if (a[i] != res[i]) {
			flag=false;
			break;
		}
	}
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}
/*
7
1 2
1 5
2 3
2 4
5 6
5 7
1 5 2 6 7 3 4
no
*/


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};
bool used[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	d[0].push_back(1);
	ed[1]=1;
	int dp=0;
	int dtp=1;
	int c=d[0].size();
	for(int i=0;i<n;i++){
		int s;
		cin>>s;
		auto t=lower_bound(d[dp].begin(),d[dp].end(),s);
		if(t!=d[dp].end() && *t==s && !used[s]){
			used[s]=1;
			for(int nex : nxt[s]) if(!ed[nex]){
				ed[nex]=1;
				d[dtp].push_back(nex);
			}
			dtp++;
			c--;
			if(c==0){
				dp++;
				c=d[dp].size();
				sort(d[dp].begin(),d[dp].end());
			}
		}else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
set<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	d[0].insert(1);
	ed[1]=1;
	int dp=0;
	int dtp=1;
	int c=d[0].size();
	for(int i=0;i<n-1;i++){
		int s;
		cin>>s;
		auto t=count(d[dp].begin(),d[dp].end(),s);
		if(t){
			for(int nex : nxt[s]) if(!ed[nex]){
				ed[nex]=1;
				d[dtp].insert(nex);
			}
			dtp++;
			c--;
			while(c==0){
				dp++;
				c=d[dp].size();
			}
		}else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	int seq[MAX];
	for(int i=0;i<n;i++)
		cin>>seq[i];

	d[0].push_back(1);
	ed[0]=1;
	int dp=0;
	while(!d[dp].empty()){
		for(int a : d[dp]){
			for(int nex : nxt[a]) if(!ed[nex]){
				ed[nex]=1;
				d[dp+1].push_back(nex);
			}
		}
		dp++;
		sort(d[dp].begin(),d[dp].end());
	}
	dp=0;
	int sp=0;
	int c=d[0].size();
	for(int i=0;i<n;i++){
		auto t=lower_bound(d[dp].begin(),d[dp].end(),seq[sp]);
		if(t!=d[dp].end() && *t==seq[sp]){
			c--;
			if(c==0){
				dp++;
				c=d[dp].size();
			}
		}else{
			cout<<"No";
			return 0;
		}
		sp++;
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	int seq[MAX];
	for(int i=0;i<n;i++)
		cin>>seq[i];

	d[0].push_back(seq[0]);
	ed[0]=1;
	int dp=0;
	while(!d[dp].empty()){
		for(int a : d[dp]){
			for(int nex : nxt[a]) if(!ed[nex]){
				ed[nex]=1;
				d[dp+1].push_back(nex);
			}
		}
		dp++;
		sort(d[dp].begin(),d[dp].end());
	}
	dp=0;
	int sp=0;
	int c=d[0].size();
	for(int i=0;i<n;i++){
		auto t=lower_bound(d[dp].begin(),d[dp].end(),seq[sp]);
		if(t!=d[dp].end() && *t==seq[sp]){
			c--;
			if(c==0){
				dp++;
				c=d[dp].size();
			}
		}else{
			cout<<"No";
			return 0;
		}
		sp++;
	}
	cout<<"YES";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	int seq[MAX];
	for(int i=0;i<n;i++)
		cin>>seq[i];

	d[0].push_back(1);
	ed[1]=1;
	int dp=0;
	int dtp=1;
	int c=d[0].size();
	for(int sp=0;sp<n;sp++){
		auto t=lower_bound(d[dp].begin(),d[dp].end(),seq[sp]);
		if(t!=d[dp].end() && *t==seq[sp]){
			for(int nex : nxt[*t]) if(!ed[nex]){
				ed[nex]=1;
				d[dtp].push_back(nex);
			}
			dtp++;
			c--;
			if(c==0){
				dp++;
				c=d[dp].size();
				sort(d[dp].begin(),d[dp].end());
			}
		}else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	d[0].push_back(1);
	ed[1]=1;
	int dp=0;
	int dtp=1;
	int c=d[0].size();
	for(int i=0;i<n;i++){
		int s;
		cin>>s;
		auto t=lower_bound(d[dp].begin(),d[dp].end(),s);
		if(t!=d[dp].end() && *t==s){
			for(int nex : nxt[s]) if(!ed[nex]){
				ed[nex]=1;
				d[dtp].push_back(nex);
			}
			dtp++;
			c--;
			if(c==0){
				dp++;
				c=d[dp].size();
				sort(d[dp].begin(),d[dp].end());
			}
		}else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
int a[MAX];
int b[MAX];
queue<int> q;
bool ed[MAX]{0};

const bool cmp(int x,int y){return a[x]<a[y];}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		a[b[i]]=i;
	}
	for(int i=1;i<=n;i++)
		sort(nxt[i].begin(),nxt[i].end(),cmp);
	q.push(1);
	ed[1]=1;
	int bp=0;
	while(!q.empty()){
		if(b[bp++]!=q.front()){
			cout<<"No";
			return 0;
		}
		for(int nex : nxt[q.front()]) if(!ed[nex]){
			ed[nex]=1;
			q.push(nex);
		}
		q.pop();
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	d[0].push_back(1);
	ed[1]=1;
	int dp=0;
	int dtp=1;
	int c=d[0].size();
	for(int i=0;i<n-1;i++){
		int s;
		cin>>s;
		auto t=lower_bound(d[dp].begin(),d[dp].end(),s);
		if(t!=d[dp].end() && *t==s){
			for(int nex : nxt[s]) if(!ed[nex]){
				ed[nex]=1;
				d[dtp].push_back(nex);
			}
			dtp++;
			c--;
			while(c==0){
				dp++;
				c=d[dp].size();
			}
			sort(d[dp].begin(),d[dp].end());
		}else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	int seq[MAX];
	for(int i=0;i<n;i++)
		cin>>seq[i];

	d[0].push_back(1);
	ed[1]=1;
	int dp=0;
	while(!d[dp].empty()){
		for(int a : d[dp]){
			for(int nex : nxt[a]) if(!ed[nex]){
				ed[nex]=1;
				d[dp+1].push_back(nex);
			}
		}
		dp++;
		sort(d[dp].begin(),d[dp].end());
	}
	dp=0;
	int sp=0;
	int c=d[0].size();
	for(int i=0;i<n;i++){
		auto t=lower_bound(d[dp].begin(),d[dp].end(),seq[sp]);
		if(t!=d[dp].end() && *t==seq[sp]){
			c--;
			if(c==0){
				dp++;
				c=d[dp].size();
			}
		}else{
			cout<<"No";
			return 0;
		}
		sp++;
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};
bool used[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	d[0].push_back(1);
	ed[1]=1;
	int dp=0;
	int dtp=1;
	int c=d[0].size();
	for(int i=0;i<n;i++){
		int s;
		cin>>s;
		auto t=lower_bound(d[dp].begin(),d[dp].end(),s);
		if(t!=d[dp].end() && *t==s && !used[s]){
			used[s]=1;
			for(int nex : nxt[s]) if(!ed[nex]){
				ed[nex]=1;
				d[dtp].push_back(nex);
			}
			dtp++;
			c--;
			while(c==0){
				dp++;
				c=d[dp].size();
				sort(d[dp].begin(),d[dp].end());
			}
		}else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=2e5+5;

static const auto __=[](){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	return nullptr;
}();

vector<int> nxt[MAX];
vector<int> d[MAX];
bool ed[MAX]{0};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nxt[a].push_back(b);
		nxt[b].push_back(a);
	}

	int seq[MAX];
	for(int i=0;i<n;i++)
		cin>>seq[i];

	d[0].push_back(1);
	ed[1]=1;
	int dp=0;
	int dtp=1;
	int c=d[0].size();
	for(int sp=0;sp<n;sp++){
		auto t=lower_bound(d[dp].begin(),d[dp].end(),seq[sp]);
		if(t!=d[dp].end() && *t==seq[sp]){
			for(int nex : nxt[*t]) if(!ed[nex]){
				ed[nex]=1;
				d[dtp].push_back(nex);
			}
			dtp++;
			c--;
			if(c==0){
				dp++;
				c=d[dp].size();
				sort(d[dp].begin(),d[dp].end());
			}
		}else{
			cout<<"No";
			return 0;
		}
		sp++;
	}
	cout<<"Yes";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    // queue<int> q;
    // q.push(1);
    // while(!q.empty())
    // {
    //     i = q.front();
    //     q.pop();
    //     visited[i] = true;
    //     bfs.push_back(i);
    //     for(j = 0; j < mp[i].size(); j++)
    //     {
    //         if(!visited[mp[i][j]])
    //             q.push(mp[i][j]);
    //     }
    // }
    // for(i = 0;i < n; i++)
    // {
    //     if(bfs[i] != sequence[i])
    //     {
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    j = 1;
    for(i = 0;i < n; i++)
    {
        while(find(mp[sequence[i]].begin(), mp[sequence[i]].end(), sequence[j]))
            j++;
    }
    if(j == n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(j);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    // queue<int> q;
    // q.push(1);
    // while(!q.empty())
    // {
    //     i = q.front();
    //     q.pop();
    //     visited[i] = true;
    //     bfs.push_back(i);
    //     for(j = 0; j < mp[i].size(); j++)
    //     {
    //         if(!visited[mp[i][j]])
    //             q.push(mp[i][j]);
    //     }
    // }
    // for(i = 0;i < n; i++)
    // {
    //     if(bfs[i] != sequence[i])
    //     {
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    j = 1;
    for(i = 0;i < n; i++)
    {
        while(find(mp[sequence[i]].begin(), mp[sequence[i]].end(), sequence[j]) != mp.end())
            j++;
    }
    if(j == n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    // queue<int> q;
    // q.push(1);
    // while(!q.empty())
    // {
    //     i = q.front();
    //     q.pop();
    //     visited[i] = true;
    //     bfs.push_back(i);
    //     for(j = 0; j < mp[i].size(); j++)
    //     {
    //         if(!visited[mp[i][j]])
    //             q.push(mp[i][j]);
    //     }
    // }
    // for(i = 0;i < n; i++)
    // {
    //     if(bfs[i] != sequence[i])
    //     {
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    j = 1;
    for(i = 0;i < n; i++)
    {
        while(find(mp[sequence[i]].begin(), mp[sequence[i]].end(), sequence[j])
            j++;
    }
    if(j == n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

void sortMap(vector<int> & sequence, int n)
{
    int i, j, k, temp;
    for(i = 1;i <= n; i++)
    {
        if(mp[i].size() == 1)
            continue;
        for(j = 0;j < mp[i].size() - 1; j++)
        {
            for(k = 0; k < mp[i].size() - j - 1; k++)
            {
                vector<int>::iterator it1 = find(sequence.begin(), sequence.end(), mp[i][j]);
                vector<int>::iterator it2 = find(sequence.begin(), sequence.end(), mp[i][k]);
                int ind1 = distance(sequence.begin(), it1);
                int ind2 = distance(sequence.begin(), it2);
                if(ind1 > ind2)
                {
                    temp = mp[i][j];
                    mp[i][j] = mp[i][k];
                    mp[i][k] = temp;
                }
            }
        }
    }
    return;
}

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    sortMap(sequence, n);
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        i = q.front();
        q.pop();
        visited[i] = true;
        bfs.push_back(i);
        for(j = 0; j < mp[i].size(); j++)
        {
            if(!visited[mp[i][j]])
                q.push(mp[i][j]);
        }
    }
    for(i = 0;i < n; i++)
    {
        if(bfs[i] != sequence[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

void sortMap(vector<int> & sequence, int n)
{
    int i, j, k, temp;
    for(i = 1;i <= n; i++)
    {
        if(mp[i].size() == 1)
            continue;
        for(j = 0;j < mp[i].size() - 1; j++)
        {
            for(k = 0; k < mp[i].size() - j - 1; k++)
            {
                vector<int>::iterator it1 = find(sequence.begin(), sequence.end(), mp[i][j]);
                vector<int>::iterator it2 = find(sequence.begin(), sequence.end(), mp[i][k]);
                int ind1 = distance(sequence.begin(), it1);
                int ind2 = distance(sequence.begin(), it2);
                if(ind1 < ind2)
                {
                    temp = mp[i][j];
                    mp[i][j] = mp[i][k];
                    mp[i][k] = temp;
                }
            }
        }
    }
    return;
}

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    sortMap(sequence, n);
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        i = q.front();
        q.pop();
        visited[i] = true;
        bfs.push_back(i);
        for(j = 0; j < mp[i].size(); j++)
        {
            if(!visited[mp[i][j]])
                q.push(mp[i][j]);
        }
    }
    for(i = 0;i < n; i++)
    {
        if(bfs[i] != sequence[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    // queue<int> q;
    // q.push(1);
    // while(!q.empty())
    // {
    //     i = q.front();
    //     q.pop();
    //     visited[i] = true;
    //     bfs.push_back(i);
    //     for(j = 0; j < mp[i].size(); j++)
    //     {
    //         if(!visited[mp[i][j]])
    //             q.push(mp[i][j]);
    //     }
    // }
    // for(i = 0;i < n; i++)
    // {
    //     if(bfs[i] != sequence[i])
    //     {
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    j = 1;
    for(i = 0;i < n; i++)
    {
        while(find(mp[sequence[i]].begin(), mp[sequence[i]].end(), sequence[j]) != mp[sequence[i]].end())
            j++;
    }
    if(j == n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

map<int, int> mp[200020];

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    //vector<int> bfs;
    //int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j][k] = 1;
        mp[k][j] = 1;
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[0] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    // queue<int> q;
    // q.push(1);
    // while(!q.empty())
    // {
    //     i = q.front();
    //     q.pop();
    //     visited[i] = true;
    //     bfs.push_back(i);
    //     for(j = 0; j < mp[i].size(); j++)
    //     {
    //         if(!visited[mp[i][j]])
    //             q.push(mp[i][j]);
    //     }
    // }
    // for(i = 0;i < n; i++)
    // {
    //     if(bfs[i] != sequence[i])
    //     {
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    j = 1;
    for(i = 0;i < n; i++)
    {
        while(mp[sequence[i]][sequence[j]])
            j++;
    }
    if(j == n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

void sortMap(vector<int> & sequence)
{
    int i, j, k, temp;
    for(i = 1;i <= n; i++)
    {
        if(mp[i].size() == 1)
            continue;
        for(j = 0;j < mp[i].size() - 1; j++)
        {
            for(k = 0; k < mp[i].size() - j - 1; k++)
            {
                if(distance(find(sequence.begin(), sequence.end(), mp[i][j]), find(sequence.begin(), sequence.end(), mp[i][k]) > 0)
                {
                    temp = mp[i][j];
                    mp[i][j] = mp[i][k];
                    mp[i][k] = temp;
                }
            }
        }
    }
    return;
}

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    sortMap(sequence);
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        i = q.front();
        q.pop();
        visited[i] = true;
        bfs.push_back(i);
        for(j = 0; j < mp[i].size(); j++)
        {
            if(!visited[mp[i][j]])
                q.push(mp[i][j]);
        }
    }
    for(i = 0;i < n; i++)
    {
        if(bfs[i] != sequence[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

void sortMap(vector<int> & sequence, int n)
{
    int i, j, k, temp;
    for(i = 1;i <= n; i++)
    {
        if(mp[i].size() == 1)
            continue;
        for(j = 0;j < mp[i].size() - 1; j++)
        {
            for(k = 0; k < mp[i].size() - j - 1; k++)
            {
                vector<int>::iterator it1 = find(sequence.begin(), sequence.end(), mp[i][k]);
                vector<int>::iterator it2 = find(sequence.begin(), sequence.end(), mp[i][k + 1]);
                int ind1 = distance(sequence.begin(), it1);
                int ind2 = distance(sequence.begin(), it2);
                if(ind1 > ind2)
                {
                    temp = mp[i][j];
                    mp[i][j] = mp[i][k];
                    mp[i][k] = temp;
                }
            }
        }
    }
    return;
}

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    sortMap(sequence, n);
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        i = q.front();
        q.pop();
        visited[i] = true;
        bfs.push_back(i);
        for(j = 0; j < mp[i].size(); j++)
        {
            if(!visited[mp[i][j]])
                q.push(mp[i][j]);
        }
    }
    for(i = 0;i < n; i++)
    {
        if(bfs[i] != sequence[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

void sortMap(vector<int> & sequence, int n)
{
    int i, j, k, temp;
    for(i = 1;i <= n; i++)
    {
        if(mp[i].size() == 1)
            continue;
        for(j = 0;j < mp[i].size() - 1; j++)
        {
            for(k = 0; k < mp[i].size() - j - 1; k++)
            {
                if(distance(find(sequence.begin(), sequence.end(), mp[i][j]), find(sequence.begin(), sequence.end(), mp[i][k]) > 0)
                {
                    temp = mp[i][j];
                    mp[i][j] = mp[i][k];
                    mp[i][k] = temp;
                }
            }
        }
    }
    return;
}

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    sortMap(sequence, n);
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        i = q.front();
        q.pop();
        visited[i] = true;
        bfs.push_back(i);
        for(j = 0; j < mp[i].size(); j++)
        {
            if(!visited[mp[i][j]])
                q.push(mp[i][j]);
        }
    }
    for(i = 0;i < n; i++)
    {
        if(bfs[i] != sequence[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

map<int, int> mp[200020];

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    //vector<int> bfs;
    //int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j][k] = 1;
        mp[k][j] = 1;
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    // queue<int> q;
    // q.push(1);
    // while(!q.empty())
    // {
    //     i = q.front();
    //     q.pop();
    //     visited[i] = true;
    //     bfs.push_back(i);
    //     for(j = 0; j < mp[i].size(); j++)
    //     {
    //         if(!visited[mp[i][j]])
    //             q.push(mp[i][j]);
    //     }
    // }
    // for(i = 0;i < n; i++)
    // {
    //     if(bfs[i] != sequence[i])
    //     {
    //         cout << "No" << endl;
    //         return 0;
    //     }
    // }
    j = 1;
    for(i = 0;i < n; i++)
    {
        while(mp[sequence[i]][sequence[j]])
            j++;
    }
    if(j == n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

unordered_map<int, vector<int>> mp;

void sortMap(vector<int> & sequence, int n)
{
    int i, j, k, temp;
    for(i = 1;i <= n; i++)
    {
        if(mp[i].size() == 1)
            continue;
        for(j = 0;j < mp[i].size() - 1; j++)
        {
            for(k = 0; k < mp[i].size() - j - 1; k++)
            {
                vector<int>::iterator it1 = find(sequence.begin(), sequence.end(), mp[i][j]);
                vector<int>::iterator it2 = find(sequence.begin(), sequence.end(), mp[i][k]);
                int ind1 = distance(sequence.begin(), it1);
                int ind2 = distance(Sequence.begin(), it2);
                if(ind1 > ind2)
                {
                    temp = mp[i][j];
                    mp[i][j] = mp[i][k];
                    mp[i][k] = temp;
                }
            }
        }
    }
    return;
}

int main()
{
    int n, i, j, k;
    cin >> n;
    vector<int> sequence(n);
    vector<int> bfs;
    int visited[n + 1] = {0};
    for(i = 0;i < n - 1; i++)
    {
        cin >> j >> k;
        mp[j].push_back(k);
        mp[k].push_back(k);
    }
    for(i = 0;i < n; i++)
        cin >> sequence[i];
    if(sequence[i] != 1)
    {
        cout << "No" << endl;
        return 0;
    }
    sortMap(sequence, n);
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        i = q.front();
        q.pop();
        visited[i] = true;
        bfs.push_back(i);
        for(j = 0; j < mp[i].size(); j++)
        {
            if(!visited[mp[i][j]])
                q.push(mp[i][j]);
        }
    }
    for(i = 0;i < n; i++)
    {
        if(bfs[i] != sequence[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll now, a[MAXN], n;
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
    if (n == 1){
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = 1; i <= n - 1; ++i){
        ll a, b;
        cin >> a >> b;
        s[a].insert(b);
        s[b].insert(a);
    }
    now = 1;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(a[1]);
    now = 2;
    for (int i = 0; i < vv.size(); ++i){
        while (1){
            if (s[vv[i]].empty() or (now == n + 1) or s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }
        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }
        if (s[vv[i]].size() && now < n){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
    } else cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll a[MAXN], n, now;
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
    for (int i = 1; i <= n - 1; ++i){
        ll a1, b1;
        cin >> a1 >> b1;
        s[a1].insert(b1);
        s[b1].insert(a1);
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(1);
    now = 1;
    for (int i = 0; i < vv.size(); ++i){
        while (1){
            if (s[vv[i]].size() == 0) break;
            if (now == n + 1) break;
            if (s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }

        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }

        if (s[vv[i]].size() > 1){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll now, a[MAXN], n;
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
    for (int i = 1; i <= n - 1; ++i){
        ll a, b;
        cin >> a >> b;
        s[a].insert(b);
        s[b].insert(a);
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(a[1]);
    now = 2;
    for (int i = 0; i < vv.size(); ++i){
        while (1){
            if (s[vv[i]].size() == 0) break;
            if (now == n + 1) break;
            if (s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }

        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }

        if (s[vv[i]].size()){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll now, a[MAXN], n;
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
    for (int i = 1; i <= n - 1; ++i){
        ll a, b;
        cin >> a >> b;
        s[a].insert(b);
        s[b].insert(a);
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(a[1]);
    now = 2;
    for (int i = 0; i < vv.size(); ++i){

        while (1){
            if (s[vv[i]].empty() or (now == n + 1) or s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }

        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }

        if (s[vv[i]].size() && now <= n){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
    } else cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll a[MAXN];
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
    for (int i = 1; i <= n - 1; ++i){
        ll a1, b1;
        cin >> a1 >> b1;
        s[a1].insert(b1);
        s[b1].insert(a1);
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(a[1]);
    now = 2;
    for (int i = 0; i < vv.size(); ++i){
        while (1){
            if (s[vv[i]].size() == 0) break;
            if (now == n + 1) break;
            if (s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }

        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }

        if (s[vv[i]].size() > 1){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll a[MAXN], n, now;
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
    for (int i = 1; i <= n - 1; ++i){
        ll a1, b1;
        cin >> a1 >> b1;
        s[a1].insert(b1);
        s[b1].insert(a1);
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(1);
    now = 2;
    for (int i = 0; i < vv.size(); ++i){
        while (1){
            if (s[vv[i]].size() == 0) break;
            if (now == n + 1) break;
            if (s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }

        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }

        if (s[vv[i]].size() > 1){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll a[MAXN], n, now;
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
   if (n == 1){cout<<"Yes"<<endl; return 0;}
    for (int i = 1; i <= n - 1; ++i){
        ll a1, b1;
        cin >> a1 >> b1;
        s[a1].insert(b1);
        s[b1].insert(a1);
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(1);
    now = 2;
      if (a[1] != 1){cout<<"No"<<endl; return 0;}
    for (int i = 0; i < vv.size(); ++i){
        while (1){
            if (s[vv[i]].size() == 0) break;
            if (now == n + 1) break;
            if (s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }

        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }

        if (s[vv[i]].size() > 1){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define pll pair <ll,ll>
#define vl vector <ll>

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1e6;
const double eps = 1e-9;
const ll mod = 1e9 + 7;
using namespace std;

ll binpow(ll a, ll n) {
    ll ans = 1;
    while (n) {
        if (n&1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}
ll now, a[MAXN], n;
set <ll> s[MAXN];
vector <ll> vv;
int main() {
    srand(time(0));
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    fast_io;
    cin >> n;
    for (int i = 1; i <= n - 1; ++i){
        ll a, b;
        cin >> a >> b;
        s[a].insert(b);
        s[b].insert(a);
    }
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vv.push_back(a[1]);
    now = 2;
    for (int i = 0; i < vv.size(); ++i){

        while (1){
            if (s[vv[i]].empty() or (now == n + 1) or s[vv[i]].find(a[now]) == s[vv[i]].end()) break;
            s[vv[i]].erase(s[vv[i]].find(a[now]));
            vv.push_back(a[now]);
            now++;
        }

        if (now == n + 1){
            cout << "Yes" << endl;
            return 0;
        }

        if (s[vv[i]].size()){
                cout << "No" << endl;
                return 0;
        }
    }

    if (now == n + 1){
        cout << "Yes" << endl;
    } else cout << "No" << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[100005];
vector<int> g2[100005];
int lev[100005];
int par[100005];
int cou[100005];

void bfs(int s)
{
	queue<int>q;
	q.push(s);
	par[s]=-1;
	lev[s]=1;
	while(!q.empty())
	{
		int top=q.front();
		q.pop();
		int sz=g[top].size();
		for(int i=0;i<sz;i++) if(lev[g[top][i]]==0)
		{
			par[g[top][i]]=top;
			cou[top]++;
			lev[g[top][i]]=lev[top]+1;
			q.push(g[top][i]);
		}
	}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,u,vv;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	cin>>u>>vv;
    	g[u].push_back(vv);
    	g[vv].push_back(u);
    }
    vector<int> v;
    int temp;
    for(int i=0;i<n;i++) cin>>temp, v.push_back(temp);

    bfs(v[0]);
	int e=1;
    for(int i=0;i<n;i++)
    {
    	int sz=cou[v[i]];
    	//cout<<sz<<endl;
    	for(int j=0;j<sz;j++)
    	{
    		//cout<<"  "<<par[v[i+e+j]]<<endl;
    		if(par[v[i+e+j]]!=v[i])
    		{
    			printf("No\n");
    			//cout<<par[3]<<endl;
    			return 0;
    		}
    	}
    	e+=sz;
    }

    printf("Yes\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
vector<int> g2[200005];
int lev[200005];
int par[200005];
int cou[200005];

void bfs(int s)
{
	queue<int>q;
	q.push(s);
	par[s]=-1;
	lev[s]=1;
	while(!q.empty())
	{
		int top=q.front();
		q.pop();
		int sz=g[top].size();
		for(int i=0;i<sz;i++) if(lev[g[top][i]]==0)
		{
			par[g[top][i]]=top;
			cou[top]++;
			lev[g[top][i]]=lev[top]+1;
			q.push(g[top][i]);
		}
	}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,u,vv;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	cin>>u>>vv;
    	g[u].push_back(vv);
    	g[vv].push_back(u);
    }
    vector<int> v;
    int temp;
    for(int i=0;i<n;i++) cin>>temp, v.push_back(temp);

    bfs(v[0]);
	int e=1;
    for(int i=0;i<n;i++)
    {
    	if(e>=n) break;
    	int sz=cou[v[i]];
    	//cout<<sz<<endl;
    	for(int j=0;j<sz;j++)
    	{
    		//cout<<"  "<<par[v[i+e+j]]<<endl;
    		if( par[v[e+j]]!=v[i])
    		{
    			printf("No\n");
    			//cout<<par[3]<<endl;
    			return 0;
    		}
    	}
    	e+=sz;
    }

    printf("Yes\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
vector<int> g2[200005];
int lev[200005];
int par[200005];
int cou[200005];

void bfs(int s)
{
	queue<int>q;
	q.push(s);
	par[s]=-1;
	lev[s]=1;
	while(!q.empty())
	{
		int top=q.front();
		q.pop();
		int sz=g[top].size();
		for(int i=0;i<sz;i++) if(lev[g[top][i]]==0)
		{
			par[g[top][i]]=top;
			cou[top]++;
			lev[g[top][i]]=lev[top]+1;
			q.push(g[top][i]);
		}
	}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,u,vv;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	cin>>u>>vv;
    	g[u].push_back(vv);
    	g[vv].push_back(u);
    }
    vector<int> v;
    int temp;
    for(int i=0;i<n;i++) cin>>temp, v.push_back(temp);

    bfs(v[0]);
	int e=1;
    for(int i=0;i<n-1;i++)
    {
    	if(e>=n) break;
    	int sz=cou[v[i]];
    	//cout<<sz<<endl;
    	for(int j=0;j<sz;j++)
    	{
    		//cout<<"  "<<par[v[i+e+j]]<<endl;
    		if( par[v[e+j]]!=v[i])
    		{
    			printf("No\n");
    			//cout<<par[3]<<endl;
    			return 0;
    		}
    	}
    	e+=sz;
    }

    printf("Yes\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
vector<int> g2[200005];
int lev[200005];
int par[200005];
int cou[200005];

void bfs(int s)
{
	queue<int>q;
	q.push(s);
	par[s]=-1;
	lev[s]=1;
	while(!q.empty())
	{
		int top=q.front();
		q.pop();
		int sz=g[top].size();
		for(int i=0;i<sz;i++) if(lev[g[top][i]]==0)
		{
			par[g[top][i]]=top;
			cou[top]++;
			lev[g[top][i]]=lev[top]+1;
			q.push(g[top][i]);
		}
	}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,u,vv;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	cin>>u>>vv;
    	g[u].push_back(vv);
    	g[vv].push_back(u);
    }
    vector<int> v;
    int temp;
    for(int i=0;i<n;i++) cin>>temp, v.push_back(temp);

    bfs(1);
	int e=1;
    for(int i=0;i<n-1;i++)
    {
    	if(e>=n) break;
    	int sz=cou[v[i]];
    	//cout<<sz<<endl;
    	for(int j=0;j<sz;j++)
    	{
    		//cout<<"  "<<par[v[i+e+j]]<<endl;
    		if(e+j<n && par[v[e+j]]!=v[i])
    		{
    			printf("No\n");
    			//cout<<par[3]<<endl;
    			return 0;
    		}
    	}
    	e+=sz;
    }

    printf("Yes\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[100005];
vector<int> g2[100005];
int lev[100005];
int par[100005];
int cou[100005];

void bfs(int s)
{
	queue<int>q;
	q.push(s);
	par[s]=-1;
	lev[s]=1;
	while(!q.empty())
	{
		int top=q.front();
		q.pop();
		int sz=g[top].size();
		for(int i=0;i<sz;i++) if(lev[g[top][i]]==0)
		{
			par[g[top][i]]=top;
			cou[top]++;
			lev[g[top][i]]=lev[top]+1;
			q.push(g[top][i]);
		}
	}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,u,vv;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	cin>>u>>vv;
    	g[u].push_back(vv);
    	g[vv].push_back(u);
    }
    vector<int> v;
    int temp;
    for(int i=0;i<n;i++) cin>>temp, v.push_back(temp);

    bfs(v[0]);
	int e=1;
    for(int i=0;i<n;i++)
    {
    	int sz=cou[v[i]];
    	//cout<<sz<<endl;
    	for(int j=0;j<sz;j++)
    	{
    		//cout<<"  "<<par[v[i+e+j]]<<endl;
    		if(i+e+j<n && par[v[i+e+j]]!=v[i])
    		{
    			printf("No\n");
    			//cout<<par[3]<<endl;
    			return 0;
    		}
    	}
    	e+=sz;
    }

    printf("Yes\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> g[100005];
vector<int> g2[100005];
int lev[100005];
int par[100005];
int cou[100005];

void bfs(int s)
{
	queue<int>q;
	q.push(s);
	par[s]=-1;
	lev[s]=1;
	while(!q.empty())
	{
		int top=q.front();
		q.pop();
		int sz=g[top].size();
		for(int i=0;i<sz;i++) if(lev[g[top][i]]==0)
		{
			par[g[top][i]]=top;
			cou[top]++;
			lev[g[top][i]]=lev[top]+1;
			q.push(g[top][i]);
		}
	}

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,u,vv;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	cin>>u>>vv;
    	g[u].push_back(vv);
    	g[vv].push_back(u);
    }
    vector<int> v;
    int temp;
    for(int i=0;i<n;i++) cin>>temp, v.push_back(temp);

    bfs(v[0]);
	int e=1;
    for(int i=0;i<n;i++)
    {
    	int sz=cou[v[i]];
    	//cout<<sz<<endl;
    	for(int j=0;j<sz;j++)
    	{
    		//cout<<"  "<<par[v[i+e+j]]<<endl;
    		if( par[v[e+j]]!=v[i])
    		{
    			printf("No\n");
    			//cout<<par[3]<<endl;
    			return 0;
    		}
    	}
    	e+=sz;
    }

    printf("Yes\n");

    return 0;
}


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

// long int dp_function_plus(int n,int sum,int x)
// {
// 	long int dp[sum+1];

//     //memset(dp,inf,sizeof(dp));

//     for(int i=0;i<=sum;i++)
//    	 dp[i]=inf;

//      dp[0]=0;
// 	for(int i=1;i<=sum;i++)
// 		for(int j=1;j<=x;j++)
// 			if(j<=i)
//               dp[i]=min(dp[i],1+dp[i-j]);

//   return dp[sum];
// }

int main()
{

   	 int n,m,x,sum=0;
     scanf("%d%d",&n,&m);

   	for( int i=0;i<n;i++)
       {scanf("%d",&x);
        sum+=x;}

   long int ans=sum/x;
   if(sum%x!=0)
   	ans++;

   	cout<<ans<<"\n";

	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX 10000

using namespace std;
typedef long long ll;

int main()
{
    ll n,x,a[MAX],sum=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(abs(sum)>x)
        cout<<abs(sum/2);
    else
        cout<<abs(sum/x);

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX 10000

using namespace std;
typedef long long ll;

int main()
{
    ll n,x,a[MAX],sum=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(abs(sum)==0)
        cout<<"0";
    else if(abs(sum)<=x)
        cout<<"1";
    else if(abs(sum)>x)
        cout<<abs(sum/x)+1;

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX 10000

using namespace std;
typedef long long ll;

int main()
{
    ll n,x,a[MAX],sum=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(abs(sum)>x)
        cout<<abs(sum/x)+1;
    else
        cout<<"1";

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX 100

using namespace std;
typedef long long ll;

int main()
{
    ll n,x,a[MAX],sum=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(abs(sum)==0)
        cout<<"0";
    else if(abs(sum)>x)
        cout<<abs(sum/x)+1;
    else if(abs(sum)<x)
        cout<<"1";

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX 100000

using namespace std;
typedef long long ll;

int main()
{
    ll n,x,a[MAX],sum=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    ll sol = abs(sum/x);
    if(sum%x!=0)
        sol+=1;
    cout<<sol;

    return 0;
}


#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);//entradas mas sficientes
  int n,x;
  cin>>n>>x;
  int suma = 0;
  for(int i=0; i<n; i++){
      int numero;
      cin >>numero;
      suma += numero;
  }
  int absoluto = abs(suma);
  if(suma==0) cout<<0<<endl;
  else if(absoluto<=x) cout<<1<<endl;
  else cout<<absoluto/x + absoluto%x;

  return (0);
}


#include <bits/stdc++.h>

using namespace std;

int main () {
  int n,x;
  cin>>n>>x;
  int suma = 0;
  for(int i=0; i<n; i++){
      int numero;
      cin >>numero;
      suma += numero;
  }
  int absoluto = abs(suma);
  if(suma==0) cout<<0<<endl;
  else if(absoluto<=x) cout<<1<<endl;
  else{
      if(absoluto%x==0) cout<<absoluto/x;
      else cout<<absoluto/x +1<<endl;
  }

  return (0);
}


#include <bits/stdc++.h>

using namespace std;

int main () {
  int n,x;
  cin>>n>>x;
  int suma = 0;
  for(int i=0; i<n; i++){
      int numero;
      cin >>numero;
      suma += numero;
  }
  int absoluto = abs(suma);
  if(suma==0) cout<<0<<endl;
  else if(absoluto<=x) cout<<1<<endl;
  else{
      int a = absoluto/x;
      int b = absoluto%x;
      cout<<a+b<<endl;
  }

  return (0);
}


#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);//entradas mas sficientes
  int n,x;
  cin>>n>>x;
  int suma = 0;
  for(int i=0; i<n; i++){
      int numero;
      cin >>numero;
      suma += numero;
  }

  if(suma==0) cout<<0<<endl;
  else if(abs(suma)<=x) cout<<1<<endl;
  else cout<<(int)abs(suma)/x + (int)abs(suma)%x;

  return (0);
}


#include <bits/stdc++.h>

using namespace std;

int main () {
  int n,x;
  cin>>n>>x;
  int suma = 0;
  for(int i=0; i<n; i++){
      int numero;
      cin >>numero;
      suma += numero;
  }
  int absoluto = abs(suma);
  if(suma==0) cout<<0<<endl;
  else if(absoluto<=x) cout<<1<<endl;
  else{
      cout<<absoluto/x +1<<endl;
  }

  return (0);
}


#include <bits/stdc++.h>

using namespace std;

int ans, sum, x, n, q;

int main()

{
    scanf("%d %d", &n, &x);
    sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin>>q;
        sum += q;
    }
    sum = abs(sum);
    ans = sum / x;
    if (sum % x != 0) ans++;
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int array[n];
    for(int i=0;i<n;i++);
    {
    cin>>array[i];
    sum=sum+arr[i];
    }
   sum=abs(sum);
   int ams=sum/x;
   if(sum%x!=0)
   cout<<++ams;
   else cout<<ams;
   return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int array[n];
    int sum=0;
    for(int i=0;i<n;i++);
    {
    cin>>array[i];
    sum=sum+arr[i];
    }
   sum=abs(sum);
   int ams=sum/x;
   if(sum%x!=0)
   cout<<++ams;
   else cout<<ams;
   return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int array[n];
    int sum=0;
    int i;
    for( i=0;i<n;i++);
    {
    cin>>array[i];
    sum=sum+array[i];
    }
   sum=abs(sum);
   int ams=sum/x;
   if(sum%x!=0)
   cout<<++ams;
   else cout<<ams;
   return 0;

}


#include <iostream>

using namespace std;
bool a[100000+10];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int x;
        cin>>x;
        a[x]=true;
    }
    for(int i=1;i<=n;i++)
    if(!a[i]){
        cout<<i;
        return 0;
    }
}


#include <iostream>

using namespace std;
int abs(int a){
    if(a>=0)
        return a;
    return -1*a;
}
int main(){
    int n,x,sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        sum+=a;
    }
    sum=abs(sum);
    if(sum%x==0)
        cout<<sum/x;
    else
        cout<<sum/x+1;
}


#include <iostream>

using namespace std;
int abs(int a){
    if(a>=0)
        return a;
    return -1*a;
}
int main(){
    int n,x,sum=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        sum+=a;
    }
    sum=abs(sum);
    if(sum%x==0)
        cout<<sum/x;
    else
        cout<<sum/x+1;
}


#include <bits/stdc++.h>
#define li long long int
#define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
    {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt","w",stdout);

        fscn

        li num,x;
        cin>>num>>x;

        li a=0,arr[num];

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

        cout<<(abs(a)+x-1)/x;

        //   cout<<a;

    }


    #include <iostream>
    #include <algorithm>
    #include <map>
    #define li long long int
    #define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    using namespace std;

    int main()
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt","w",stdout);

        fscn

        li num,x;
        cin>>num>>x;

        li a=0,arr[num],f=1;

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

        if(a%x)
           a++;

           cout<<a;

    }


#include <iostream>
    #include <algorithm>
    #include <map>
    #define li long long int
    #define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    using namespace std;

    int main()
    {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt","w",stdout);

        fscn

        li num,x;
        cin>>num>>x;

        li a=0,arr[num],f=1;

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

        a/=x;
        if(a%x)
           a++;

           cout<<a;

    }


#include <iostream>
#include <algorithm>
#include <map>
#define li long long int
#define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);

    fscn

    li num,x;
    cin>>num>>x;

    li a,arr[num];
        map <li,li> chart;

    for(int  i=0;i<num;i++)
    {
        cin>>arr[i];
        a=abs(arr[i]);

        if(a>x)
        {
            f=0;
            cout<<"-1";
            return 0;
        }

        chart[a]+=arr[i];

    }

    li c=0;
     for (auto i : chart) {
        if(i.second != 0)
           c+= abs(i.second/i.first);
           }
    cout<<c;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#define li long long int
#define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);

    fscn

    li num,x;
    cin>>num>>x;

    li a=0,arr[num],f=1;

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

    if(a%b)
       a++;

       cout<<a;

}


#include <iostream>
    #include <algorithm>
    #include <map>
    #define li long long int
    #define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    using namespace std;

    int main()
    {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt","w",stdout);

        fscn

        li num,x;
        cin>>num>>x;

        li a=0,arr[num],f=1;

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

        if(a%x)
           a++;

           cout<<a;

    }


#include <iostream>
    #include <algorithm>
    #include <map>
    #define li long long int
    #define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    using namespace std;

    int main()
    {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt","w",stdout);

        fscn

        li num,x;
        cin>>num>>x;

        li a=0,arr[num],f=1;

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

        li b=abs(a)+x-1;
        b/=x;

           cout<<a;

    }


#include <iostream>
#include <algorithm>
#include <map>
#define li long long int
#define fscn ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);

    fscn

    li num,x;
    cin>>num>>x;

    li a,arr[num],f=1;
        map <li,li> chart;

    for(int  i=0;i<num;i++)
    {
        cin>>arr[i];
        a=abs(arr[i]);

        if(a>x)
        {
            f=0;
            cout<<"-1";
            return 0;
        }

        chart[a]+=arr[i];

    }

   if(f){
     li c=0;
     for (auto i : chart) {
        if(i.second != 0)
           c+= abs(i.second/i.first);
           }
    cout<<c;

   }
    return 0;
}


#include <bits/stdc++.h>
#define li long long int
#define fsc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
    {
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt","w",stdout);

        fsc

        li num,x;
        cin>>num>>x;

        li a=0,arr[num];

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

        cout<<(abs(a)+x-1)/x;

        //   cout<<a;

    }


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	int x;
	cin>>n>>x;
	int a[n];
	int num=0;
	for(int i=0;i<n;i++)
	{

		cin>>a[i];
		num=num+a[i];
	}
	if(abs(num)>abs(x))
	{
		cout<<abs(num)/abs(x)+1;
	}
	if(abs(num)<=abs(x))
		cout<<1;

}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	int x;
	cin>>n>>x;
	int a[n];
	int num=0;
	for(int i=0;i<n;i++)
	{

		cin>>a[i];
		num=num+a[i];
	}
	if(abs(num)>abs(x))
	{
		cout<<num/2+1;
	}
	if(abs(num)<abs(x))
		cout<<1;

}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	int x;
	cin>>n>>x;
	int a[n];
	int num=0;
	for(int i=0;i<n;i++)
	{

		cin>>a[i];
		num=num+a[i];
	}
	if(num==0)
	{
		cout<<0;
		return 0;

	}

	if(abs(num)>abs(x))
	{
		cout<<abs(num)/abs(x)+1;
	}
	else if(abs(num)<=abs(x))
		cout<<1;

}


#include<iostream>
using namespace std;
int main()
{
	int n,int x;
	cin>>n>>x;
	int a[n];
	for(int i=0;i<n;i++)
	{
		int num=0;
		cin>>a[i];
		num=num+a[i];
	}
	if(abs(num)>abs(x))
	{
		cout<<num/2+1;
	}
	if(abs(num)<abs(x))
		cout<<1;

}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	int x;
	cin>>n>>x;
	int a[n];
	int num=0;
	for(int i=0;i<n;i++)
	{

		cin>>a[i];
		num=num+a[i];
	}
	if(num==0)
	{
		cout<<0;
		return 0;

	}

	if(abs(num)>abs(x))
	{
		if(abs(num)%abs(x)==0)
			cout<<abs(num)/abs(x);
		else
			cout<<abs(num)/abs(x)+1;
	}
	else if(abs(num)<=abs(x))
		cout<<1;

}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	int x;
	cin>>n>>x;
	int a[n];
	int num=0;
	for(int i=0;i<n;i++)
	{

		cin>>a[i];
		num=num+a[i];
	}
	if(abs(num)>abs(x))
	{
		cout<<num/2+1;
	}
	if(abs(num)<=abs(x))
		cout<<1;

}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

#endif
	int n, x;
	cin >> n >> x;

	int sum = 0;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		sum += temp;
	}
	if (sum == 0) {
		cout << 0;
		return 0;
	}
	int count = 0;
	int pos = abs(sum);
	do {
		count++;
		pos -= x;
	} while (pos >= x || pos >= 1 );
	cout << count;
}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

#endif
	int n, x;
	cin >> n >> x;

	int sum = 0;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		sum += temp;
	}
	int count = 0;
	int pos = abs(sum);
	do {
		count++;
		pos -= x;
	} while (pos >= x || pos >= 1 );
	cout << count;
}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

#endif
	int n, x;
	cin >> n >> x;

	int sum = 0;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		sum += temp;
	}
	int count = 0;
	int pos = abs(sum);
	do {
		count++;
		pos -= x;
	} while (pos >= x || pos >= 1 );
	cout << abs(sum) << " " << sum << endl;
	cout << count;
}