#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <string>
#define REP(i,j) for(int i=1;i<=j;++i)
#define REPI(i,j,k) for(int i=j;i<=k;++i)
#define REPD(i,j) for(int i=j;0<i;--i)
#define CLR(s) memset(s,0,sizeof s)
#define SET(s,v) memset(s,v,sizeof s)
#define mp make_pair
#define pb push_back
#define x first
#define y second
using namespace std;
string FILE_NAME = "meat";
typedef long long LL;
typedef double DB;
const int INF = 0x3f3f3f3f;
const int maxn = 500000 + 500;
int fa[maxn],son[maxn],n;
DB A[maxn],F[maxn];
struct Edge
{
int head[maxn],next[maxn],to[maxn];
int edge;
void init()
{
edge=0;
SET(head,-1);
}
void addedge(int a,int b)
{
next[edge]=head[a];
to[edge]=b;
head[a]=edge++;
}
}E;
int cnt;
int dcmp(DB d)
{
if(fabs(d)<1e-8)
return 0;
return d<0?-1:1;
}
DB add[maxn];
void dfs(int t)
{
if(son[t]==0) return ;
for(int i=E.head[t];i!=-1;i=E.next[i])
{
F[E.to[i]]=F[t]+add[t];
dfs(E.to[i]);
}
}
bool cmp(DB a,DB b)
{
return dcmp(a-b)<0;
}
int main()
{
scanf("%d",&n);
E.init();
for(int i=1;i<=n;++i)
{
scanf("%lf",&A[i]);
}
for(int i=1;i<n;++i)
{
int a,b;
scanf("%d%d",&a,&b);
fa[b]=a;
++son[a];
E.addedge(a,b);
}
for(int i=1;i<=n;++i)
{
add[i]=log(son[i]);
}
F[1]=0;
dfs(1);
for(int i=1;i<=n;++i)
{
F[i]+=log(A[i]);
}
sort(F+1,F+n+1,cmp);
int ans=0;
for(int i=1;i<=n;++i)
{
int cnt=1;
while(dcmp(F[i]-F[i+1])==0 && i+1<=n)
{
++cnt;
++i;
}
if(cnt>ans)
ans=cnt;
}
printf("%d\n",n-ans);
return 0;
}
I2luY2x1ZGUgPGNzdGR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