/*Coded by::
**Avinash Tiwary**
**BE/10298/2015**
**Production Engineer**
**Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define INF 1e18
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define mp make_pair
#define mt make_tuple
#define pb push_back
unordered_map<int,int>conr, con;
ll n,block,ar[M5],st[M5],en[M5],dep[M5],out[M5],par[M5][20],answer=0,timer=0,kha[M5];
struct query{
ll l,r,i,p;
}q[M5];
bool comp(query a,query b){
if(a.l/block!=b.l/block) return a.l<b.l;
return a.r<b.r;
}
vector<list<ll> >g(M5);
void dfs(ll cur,ll p){
dep[cur]=dep[p]+1;
par[cur][0]=p;
timer++;
st[cur]=timer;
kha[timer]=cur;
for(auto it=g[cur].begin();it!=g[cur].end();it++) if(*it!=p) dfs(*it,cur);
timer++;
en[cur]=timer;
kha[timer]=cur;
}
void preLCA(){
for(ll i=1;i<log2(n)+1;i++){
for(ll j=1;j<=n;j++){
if(par[j][i-1]!=-1)
par[j][i]=par[par[j][i-1]][i-1];
}
}
}
ll lca(ll u,ll v){
if(dep[u]>dep[v]) swap(u,v);
ll dif=dep[v]-dep[u];
while(dif>0){
ll up=log2(dif);
v=par[v][up];
dif-=(1<<up);
}
if(u==v) return u;
for(ll i=log2(n)+1;i>=0;i--) if(par[u][i]!=par[v][i]){u=par[u][i]; v=par[v][i];}
return par[u][0];
}
void add(ll i){
con[i]++;
if(con[i]==1){
conr[ar[i]]++;
if(conr[ar[i]]==1) answer++;
}
if(con[i]==2){
conr[ar[i]]--;
if(conr[ar[i]]==0) answer--;
}
}
void remove(ll i){
con[i]--;
if(con[i]==1){
conr[ar[i]]++;
if(conr[ar[i]]==1) answer++;
}
if(con[i]==0){
conr[ar[i]]--;
if(conr[ar[i]]==0) answer--;
}
}
int main(){
//buf;
//sieve();
//fact();
ll l,r,i,j,test,ans,m,k,a,b; //string s;
//cin>>test;
test=1;
while(test--){
cin>>n>>m;
for(i=1;i<=n;i++) cin>>ar[i];
i=1;
while(i<n){
cin>>a>>b;
g[a].pb(b); g[b].pb(a);
i++;
}
memset(par,-1,sizeof(par));
dep[0]=-1; dfs(1,0);
//for(i=1;i<=n;i++) cout<<st[i]<<" "<<en[i]<<endl;
block=timer/sqrt(timer);
preLCA();
for(i=0;i<m;i++){
cin>>a>>b;
q[i].i=i;
ll l=lca(a,b);
if(st[a]>st[b]) swap(a,b);
if(l==a||l==b){
q[i].l=st[a]; q[i].r=st[b]; q[i].p=-1;
}
else{
q[i].l=en[a]; q[i].r=st[b]; q[i].p=l;
}
}
block=timer/sqrt(timer);
sort(q,q+m,comp);
ll cl=1,cr=1; add(1);
//for(i=1;i<=timer;i++) cout<<kha[i]<<" ";
//cout<<endl;
for(i=0;i<m;i++){
ll u=q[i].l,v=q[i].r;
//cout<<q[i].i<<" "<<u<<" "<<v<<" "<<q[i].p<<endl;
while(cl<u){
remove(kha[cl]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cl++;
}
//cout<<endl;
while(cl>u){
add(kha[cl+1]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cl--;
}
//cout<<endl;
while(cr>v){
remove(kha[cr]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cr--;
}
//cout<<endl;
while(cr<v){
add(kha[cr+1]);
//for(j=1;j<=n;j++) cout<<conr[ar[j]]<<" "; cout<<endl;
cr++;
}
//cout<<endl;
if(q[i].p!=-1&&con[ar[q[i].p]]==0) out[i]=answer+1;
else out[i]=answer;
//cout<<out[i]<<endl;
}
for(i=0;i<m;i++) cout<<out[i]<<endl;
}
return 0;
}
LypDb2RlZCBieTo6CiAgICAqKkF2aW5hc2ggVGl3YXJ5KioKICAgICoqQkUvMTAyOTgvMjAxNSoqCiAgICA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ltZXI7CiAgICBraGFbdGltZXJdPWN1cjsKICAgIGZvcihhdXRvIGl0PWdbY3VyXS5iZWdpbigpO2l0IT1nW2N1cl0uZW5kKCk7aXQrKykgaWYoKml0IT1wKSBkZnMoKml0LGN1cik7CiAgICB0aW1lcisrOwogICAgZW5bY3VyXT10aW1lcjsKICAgIGtoYVt0aW1lcl09Y3VyOwp9CnZvaWQgcHJlTENBKCl7CiAgICBmb3IobGwgaT0xO2k8bG9nMihuKSsxO2krKyl7CiAgICAgICAgZm9yKGxsIGo9MTtqPD1uO2orKyl7CiAgICAgICAgICAgIGlmKHBhcltqXVtpLTFdIT0tMSkKICAgICAgICAgICAgICAgIHBhcltqXVtpXT1wYXJbcGFyW2pdW2ktMV1dW2ktMV07CiAgICAgICAgfQogICAgfQp9CmxsIGxjYShsbCB1LGxsIHYpewogICAgaWYoZGVwW3VdPmRlcFt2XSkgc3dhcCh1LHYpOwogICAgbGwgZGlmPWRlcFt2XS1kZXBbdV07CiAgICB3aGlsZShkaWY+MCl7CiAgICAgICAgbGwgdXA9bG9nMihkaWYpOwogICAgICAgIHY9cGFyW3ZdW3VwXTsKICAgICAgICBkaWYtPSgxPDx1cCk7CiAgICB9CiAgICBpZih1PT12KSByZXR1cm4gdTsKICAgIGZvcihsbCBpPWxvZzIobikrMTtpPj0wO2ktLSkgaWYocGFyW3VdW2ldIT1wYXJbdl1baV0pe3U9cGFyW3VdW2ldOyB2PXBhclt2XVtpXTt9CiAgICByZXR1cm4gcGFyW3VdWzBdOwp9CnZvaWQgYWRkKGxsIGkpewogICAgY29uW2ldKys7CiAgICBpZihjb25baV09PTEpeyAKICAgICAgICBjb25yW2FyW2ldXSsrOwogICAgICAgIGlmKGNvbnJbYXJbaV1dPT0xKSBhbnN3ZXIrKzsKICAgIH0KICAgIGlmKGNvbltpXT09Mil7IAogICAgICAgIGNvbnJbYXJbaV1dLS07CiAgICAgICAgaWYoY29uclthcltpXV09PTApIGFuc3dlci0tOwogICAgfQp9CnZvaWQgcmVtb3ZlKGxsIGkpewogICAgY29uW2ldLS07CiAgICBpZihjb25baV09PTEpeyAKICAgICAgICBjb25yW2FyW2ldXSsrOwogICAgICAgIGlmKGNvbnJbYXJbaV1dPT0xKSBhbnN3ZXIrKzsKICAgIH0KICAgIGlmKGNvbltpXT09MCl7IAogICAgICAgIGNvbnJbYXJbaV1dLS07CiAgICAgICAgaWYoY29uclthcltpXV09PTApIGFuc3dlci0tOwogICAgfQp9CmludCBtYWluKCl7CiAgICAvL2J1ZjsgCiAgICAvL3NpZXZlKCk7IAogICAgLy9mYWN0KCk7CiAgICBsbCBsLHIsaSxqLHRlc3QsYW5zLG0sayxhLGI7IC8vc3RyaW5nIHM7CiAgICAvL2Npbj4+dGVzdDsKICAgIHRlc3Q9MTsKICAgIHdoaWxlKHRlc3QtLSl7CiAgICAgICAgY2luPj5uPj5tOwogICAgICAgIGZvcihpPTE7aTw9bjtpKyspIGNpbj4+YXJbaV07CiAgICAgICAgaT0xOwogICAgICAgIHdoaWxlKGk8bil7CiAgICAgICAgICAgIGNpbj4+YT4+YjsKICAgICAgICAgICAgZ1thXS5wYihiKTsgZ1tiXS5wYihhKTsKICAgICAgICAgICAgaSsrOwogICAgICAgIH0KICAgICAgICBtZW1zZXQocGFyLC0xLHNpemVvZihwYXIpKTsKICAgICAgICBkZXBbMF09LTE7IGRmcygxLDApOwogICAgICAgIC8vZm9yKGk9MTtpPD1uO2krKykgY291dDw8c3RbaV08PCIgIjw8ZW5baV08PGVuZGw7CiAgICAgICAgYmxvY2s9dGltZXIvc3FydCh0aW1lcik7CiAgICAgICAgcHJlTENBKCk7CiAgICAgICAgZm9yKGk9MDtpPG07aSsrKXsKICAgICAgICAgICAgY2luPj5hPj5iOwogICAgICAgICAgICBxW2ldLmk9aTsKICAgICAgICAgICAgbGwgbD1sY2EoYSxiKTsKICAgICAgICAgICAgaWYoc3RbYV0+c3RbYl0pIHN3YXAoYSxiKTsKICAgICAgICAgICAgaWYobD09YXx8bD09Yil7CiAgICAgICAgICAgICAgICBxW2ldLmw9c3RbYV07IHFbaV0ucj1zdFtiXTsgcVtpXS5wPS0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICBxW2ldLmw9ZW5bYV07IHFbaV0ucj1zdFtiXTsgcVtpXS5wPWw7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgYmxvY2s9dGltZXIvc3FydCh0aW1lcik7CiAgICAgICAgc29ydChxLHErbSxjb21wKTsKICAgICAgICBsbCBjbD0xLGNyPTE7IGFkZCgxKTsKICAgICAgICAvL2ZvcihpPTE7aTw9dGltZXI7aSsrKSBjb3V0PDxraGFbaV08PCIgIjsKICAgICAgICAvL2NvdXQ8PGVuZGw7CiAgICAgICAgZm9yKGk9MDtpPG07aSsrKXsKICAgICAgICAgICAgbGwgdT1xW2ldLmwsdj1xW2ldLnI7CiAgICAgICAgICAgIC8vY291dDw8cVtpXS5pPDwiICI8PHU8PCIgIjw8djw8IiAiPDxxW2ldLnA8PGVuZGw7CiAgICAgICAgICAgIHdoaWxlKGNsPHUpewogICAgICAgICAgICAgICAgcmVtb3ZlKGtoYVtjbF0pOwogICAgICAgICAgICAgICAgLy9mb3Ioaj0xO2o8PW47aisrKSBjb3V0PDxjb25yW2FyW2pdXTw8IiAiOyBjb3V0PDxlbmRsOwogICAgICAgICAgICAgICAgY2wrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICAvL2NvdXQ8PGVuZGw7CiAgICAgICAgICAgIHdoaWxlKGNsPnUpewogICAgICAgICAgICAgICAgYWRkKGtoYVtjbCsxXSk7CiAgICAgICAgICAgICAgICAvL2ZvcihqPTE7ajw9bjtqKyspIGNvdXQ8PGNvbnJbYXJbal1dPDwiICI7IGNvdXQ8PGVuZGw7CiAgICAgICAgICAgICAgICBjbC0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vY291dDw8ZW5kbDsKICAgICAgICAgICAgd2hpbGUoY3I+dil7CiAgICAgICAgICAgICAgICByZW1vdmUoa2hhW2NyXSk7CiAgICAgICAgICAgICAgICAvL2ZvcihqPTE7ajw9bjtqKyspIGNvdXQ8PGNvbnJbYXJbal1dPDwiICI7IGNvdXQ8PGVuZGw7CiAgICAgICAgICAgICAgICBjci0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vY291dDw8ZW5kbDsKICAgICAgICAgICAgd2hpbGUoY3I8dil7CiAgICAgICAgICAgICAgICBhZGQoa2hhW2NyKzFdKTsKICAgICAgICAgICAgICAgIC8vZm9yKGo9MTtqPD1uO2orKykgY291dDw8Y29uclthcltqXV08PCIgIjsgY291dDw8ZW5kbDsKICAgICAgICAgICAgICAgIGNyKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy9jb3V0PDxlbmRsOwogICAgICAgICAgICBpZihxW2ldLnAhPS0xJiZjb25bYXJbcVtpXS5wXV09PTApIG91dFtpXT1hbnN3ZXIrMTsKICAgICAgICAgICAgZWxzZSBvdXRbaV09YW5zd2VyOwogICAgICAgICAgICAvL2NvdXQ8PG91dFtpXTw8ZW5kbDsKICAgICAgICB9CiAgICAgICAgZm9yKGk9MDtpPG07aSsrKSBjb3V0PDxvdXRbaV08PGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==