#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;
/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
/* MACROS */ 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;
typedef tuple<int,int,int> tup;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  lcm(x, y)   ((x) * (y) / __gcd(x, y))
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 1e5 + 3;

vi node_col(MAX_N),vis(MAX_N , 0),adj[MAX_N];
mii mp;
set<int>ans;

void dfs(int node){
    vis[node] = 1;
    mp[node_col[node]]++;
    if(mp[node_col[node]]==1){
        ans.insert(node);
    }

    for(auto x:adj[node]){
        if(!vis[x]){
            dfs(x);
        }
    }
    
    mp[node_col[node]]--;
}

void solve(){
    int n; cin >> n;
    rep(i,1,n+1) cin >> node_col[i];
    
    rep(i,1,n){
        int a,b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    
    dfs(1);
    
    for(auto x:ans) cout << x << "\n";
}

int main(){
    IOS;
    solve();
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define F first
#define S second
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,greater<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

ll n;
ve<ll> ch(205,-1),val(205,-1),dp(205,-1);

bool com(ll a, ll b)
{
    if(ch[a]==1 || ch[b]==0 || (val[a]!=-1 && val[a]!=b) || (val[b]!=-1 && val[b]!=a) || (ch[a]==0 && ch[b]==1 && val[a]==-1 && val[b]==-1))
        return false;
    return true;
}

void fun(ll x)
{
    if(dp[x]!=-1)
        return;
    ll p=(x+n+n+1)/2;
    bool ans=0;
    for(ll i=x+1;i<=p;i++)
    {
        bool b=1;
        for(ll j=x,k=i;j<i;j++,k++)
            b=(b && com(j,k));
        if(b)
        {
            fun(i+i-x);
            ans=(ans || (dp[i+i-x]==1));
        }
    }
    if(ans)
        dp[x]=1;
    else
        dp[x]=0;
}

int main() 
{
    FAST;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        if(a!=-1)
        {
            if(ch[a]!=-1)
            {
                cout<<"No";
                return 0;
            }
            ch[a]=0;
            val[a]=b;
        }
        if(b!=-1)
        {
            if(ch[b]!=-1)
            {
                cout<<"No";
                return 0;
            }
            ch[b]=1;
            val[b]=a;
        }
    }
    dp[n+n+1]=1;
    fun(1);
    if(dp[1]==1)
        cout<<"Yes";
    else
        cout<<"No";
    subt;
    return 0;
}