#include <bits/stdc++.h>

using namespace std;

int BIG = 9999999;

vector<int> interests;
vector<int> vinterests;
vector<int> kapairs;
int nums[400001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t, a, b, c, d, n, ans = 0;
    long long int w, x, y, z;
    cin >> n;
    d = 0;
    kapairs.resize(400001);
    for(int i = 0; i < 400001; i++) {
        kapairs[i] = 0;
    }
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        nums[a]++; nums[b]++;
        kapairs[a] += b;
        kapairs[b] += a;
    }
    for(int i = 0; i < 400001; i++) {
        if(nums[i]) d++;
        if(nums[i] == 1) interests.push_back(i);
    }
    // cout << "yay\n";
    while(interests.size()) {
        for(int i = 0; i < interests.size(); i++) {
            d--;
            if(kapairs[interests[i]] == 0) continue;
            int c = kapairs[interests[i]], k = interests[i];
            kapairs[k] -= c;
            kapairs[c] -= k;
            nums[k]--; nums[c]--;
            if(nums[c] == 1) vinterests.push_back(c);
            ans++;
        }
        interests.swap(vinterests);
        vector<int>().swap(vinterests);
    }
    // cout << "Left with " << numnums[0].first << ' ' << numnums[0].second << '\n';
    cout << ans+d << '\n';
}
//Shinchan Loves Coding :))
#include<bits/stdc++.h>

using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define double long double
#define int long long int
#define en "\n"
#define fi first
#define se second
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define rep(i,x,y) for(int i=x ; i<y ; i++)
#define erep(i,x,y) for(int i=x ; i<=y ; i++)
#define erepr(i,x,y) for(int i=x ; i>=y ; i--)
#define repr(i,x,y) for(int i=x ; i>y ; i--)

typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------

const int no=3e6+5,modulo=1e9+7,inf=1e18,N=2e3+1;
const double PI = 3.1415926535897932384;
int ar[no] ,br[no],cr[no];//,dr[no],er[no];
int used[no];
//int color[no];
//pii adj[no];
vi adj[no] ;
//LOWER_BOUND(n) - FIRST ELEMENT GREATER THAN EQUAL TO n
//UPPER_BOUND(n) - FIRST ELEMENT GREATER THAN n

//--------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                        

int mark[no];
vi ans;

void dfs(int node) {
    used[node]=1;
    if(!mark[ar[node]]) ans.PB(node);
    mark[ar[node]]++;
    for(int child : adj[node]) {
        if(!used[child]) {
            dfs(child);
        }
    }
    mark[ar[node]]--;
}

void solve () {
    int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0,w=0,k=0; 
    cin>>n;
    rep(i,1,n+1) cin>>ar[i];
    m=n-1;
    rep(i,0,m) {
        cin>>x>>y;
        adj[x].PB(y);
        adj[y].PB(x);
    }
    dfs(1);
    sort(all(ans));
    for(auto ii : ans) cout<<ii<<en;
}

inline void runn() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);      
    freopen("output.txt","w",stdout);   
    #endif
}

signed main() {
    night_rider
    runn(); 
    int t=1;
    cout<<fixed<<setprecision(15);
  //  cin>>t;
    rep(i,1,t+1) {
       // cout << "Case #" << i << ": ";
        solve();
    }
}
