#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,m,ans;
vector<int> adj[400001];
vector<int> cur;
bool vis[400001];
void dfs(int x){
    vis[x]=true;
    cur.pb(x);
    for (auto i:adj[x]){
        if (vis[i]) continue;
        dfs(i);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>m;
    n=400000;
    for (int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    for (int i=1;i<=n;i++){
        if (vis[i] || adj[i].empty()) continue;
        cur.clear();
        dfs(i);
        int curnum=cur.size(),edges=0;
        for (auto j:cur){
            edges+=adj[j].size();
        }
        edges/=2;
        ans+=min(curnum,edges);
    }
    cout<<ans;
}
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define isSet(n, i) bool(n & (1LL << i))
#define Set(n, i) (n | (1LL << i))
#define unSet(n, i) (n & !(1LL << i))
#define PI 2 * acos(0.0)
#define all(r) (r).begin(), (r).end()
#define dbg(a) cout << #a << " ->->->-> " << a << "\n"
#define inf 100000000000000000
#define mod 1000000007
#define N 100009

int dirx[] = {1, -1, 0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1};

//=============================================ASIFAZAD==============================================//

int n, ans[N], colors[N], cur[N];
vi adj[N];

void dfs(int nod, int par)
{
    if (cur[colors[nod]])
        ans[nod] = -1;
    else
        ans[nod] = 1;
    cur[colors[nod]]++;
    for (auto x : adj[nod])
        if (x != par)
            dfs(x, nod);
    cur[colors[nod]]--;
}

int main()
{
    io;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &colors[i]);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        u--;
        v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(0, -1);
    for (int i = 0; i < n; i++)
        if (ans[i] == 1)
            printf("%d\n", i + 1);
    return 0;
}