#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mpi map<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define pl pair<ll,ll>
#define pi pair<int,int>
#define forn(i,n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf       1000000000000
#define MOD       1000000007
ll binpow(ll a,ll b,ll m){
    a%=m;
    ll res=1;
    while(b>0){
        if(b&1)
            res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
vl edge[100005];
ll c[100005];
ll vis[100005];
vl ans;
map<ll,ll> mp;
void dfs(ll n){
    vis[n]=1;
    forn(i,edge[n].size()){
        if(vis[edge[n][i]]==0){
            if(mp[c[edge[n][i]]]==0){
                ans.pb(edge[n][i]);
            }
            mp[c[edge[n][i]]]++;
            dfs(edge[n][i]);
            mp[c[edge[n][i]]]--;
        }
    }
}
void solve(){
    ll n;
    cin>>n;
    forn(i,n)
    cin>>c[i+1];
    forn(i,n-1){
        ll x,y;
        cin>>x>>y;
        edge[x].pb(y);
        edge[y].pb(x);
    }
    forn(i,n)
    vis[i+1]=0;
    ans.pb(1);
    mp[c[1]]++;
    dfs(1);
    sort(ans.begin(),ans.end());
    forn(i,ans.size())
    cout<<ans[i]<<endl;
}

int main() {

    ll t=1;
    while(t--)
	{
        solve();
		cout<<endl;
    }

    return 0;
}

// Problem: B - Reversible Cards
// Contest: AtCoder - AtCoder Regular Contest 111
// URL: https://atcoder.jp/contests/arc111/tasks/arc111_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> g[400002];
int vis[400002];
pair<int, int> dfs1(int u, int v) {
  if (vis[u]) return {0, 0};
  vis[u] = true;
  int res1 = 1;
  int res2 = g[u].size();
  for (int x : g[u]) {
    if (x == v || x == u) continue;
    auto c = dfs1(x, u);
    res1 += c.first;
    res2 += c.second;
  }
  return {res1, res2};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int sum = 0;
  for (int i = 0; i < 400002; i++) {
    if (g[i].size() && vis[i] == 0) {
      auto c = dfs1(i, 0);
      if (c.second / 2 < c.first) {
        sum--;
      }
      sum += c.first;
    }
  }

  cout << sum << endl;
}