#include <bits/stdc++.h>
using namespace std;
const int inf=200005;
vector < int > graph[inf];
int n;
bool visit[inf];
int color[inf];
int count1=0,count2=0;
void dfs(int a,int b)
{
	if(visit[a])
	return ;
	
	for(int v:graph[a])
	if(!visit[v] && color[v] != b )
	{
		dfs(v,b);
	}
 } 
int main() {
	cin>>n;
	for(int a=0;a<n;a++)
	{
		cin>>color[a];
		
	}
	for(int a=0;a<n-1;a++)
	{
		int x,y;
		cin>>x>>y;
		graph[x].push_back(y);
		graph[y].push_back(x);
		
	}
	
	for(int a=0;a<n;a++)
	{
		if(color[a]==0 && !visit[a])
		{
			dfs(a,1);
			count1++;
		}
		else
		if(!visit[a])
		{
			dfs(a,0);
			count2++;
		}
	}
	
	cout<< min(count2,count1);

}
