//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
typedef long long ll;
#define REP(i,n) for(register int i=0;i<(n);++i)
#define REP1(i,a,b) for(register int i=(a);i<=(b);++i)
#define em emplace_back
#define mkp make_pair
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define Rosario ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//#define lb(x) (x&-x)

int ans,n,eg,cnt,mx;
vector<int> v[400005];
bool vis[400005];
void dfs(int x,int p){
	vis[x]=1; ++cnt;
	for(auto &i:v[x]) {
		if(i!=p) ++eg;
		if(!vis[i]) dfs(i,x);
	}
}
int main(){Rosario
	cin>>n;
	for(int x,y,i=0;i<n;++i) {
		cin>>x>>y;
		v[x].em(y),v[y].em(x),mx=max({mx,x,y});
	}
	REP1(i,1,mx) if(!vis[i]&&!v[i].empty()){
		eg=cnt=0; dfs(i,0);
		if(cnt==eg+1) ans+=eg;
		else ans+=cnt;
	}
	cout<<ans;
	return 0;
}
/**
 *  In The Name Of God
 *  author : Behradm
 *  Idvwhu wkdq idvw, Txlfnhu wkdq txlfn, L dp Oljkwqlqj, Vshhg, L dp Vshhg.
**/
#include "bits/stdc++.h"

using namespace std;

const int N = 1e5 + 11;
int c[N];
bool mk[N];
int col[N];
vector<vector<int>> g;
vector<int> out;

void dfs(int u) {
  if (col[c[u]] == 0)
    out.push_back(u);

  mk[u] = 1;
  col[c[u]]++;
  for (int v : g[u]) {
    if (mk[v])
      continue;
    dfs(v);
  }
  col[c[u]]--;
  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> c[i];
  g.resize(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  dfs(1);
  sort(out.begin(), out.end());
  for (int u : out)
    cout << u << '\n';
  return 0;
}


