语文题。。。
原来除了hash还可以取对数啊orz
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define maxv 500500
#define maxe 1000500
using namespace std;
int n,val[maxv],son[maxv],x,y,g[maxv],nume=,fath[maxv],ret,ans=;
double r[maxv],stack[maxv],mx;
queue <int> q;
struct edge
{
int v,nxt;
}e[maxe];
void addedge(int u,int v)
{
e[++nume].v=v;
e[nume].nxt=g[u];
g[u]=nume;
}
void bfs()
{
while (!q.empty()) q.pop();
q.push();r[]=;
while (!q.empty())
{
int head=q.front();q.pop();son[head]=;
for (int i=g[head];i;i=e[i].nxt)
{
int v=e[i].v;
if (v!=fath[head])
{
fath[v]=head;
son[head]++;
q.push(v);
}
}
for (int i=g[head];i;i=e[i].nxt)
{
int v=e[i].v;
if (v!=fath[head])
r[v]=r[head]+log(son[head]);
}
}
}
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%d",&val[i]);
for (int i=;i<=n-;i++)
{
scanf("%d%d",&x,&y);
addedge(x,y);
addedge(y,x);
}
bfs();
for (int i=;i<=n;i++)
stack[i]=r[i]+log(val[i]);
sort(stack+,stack+n+);
ret=;
for (int i=;i<=n+;i++)
{
if (fabs(stack[i-]-stack[i])<1e-)
ret++;
else {ans=max(ans,ret);ret=;}
}
printf("%d\n",n-ans);
return ;
}