func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4, inf = 1e9 + 7;   vector<int> vec[N];   vector<pair<int, int> > qry[N];   int col[N], cnt[N], frq[N];   int vis[N], siz[N], Res[N];   void dfs(int u, int p) {     siz[u] = 1;     for (auto v : vec[u]) {       if (v == p) continue;       dfs(v, u);       siz[u] += siz[v];     }   }   void Add(int u, int p) {     cnt[++frq[col[u]]]++;     for (auto v : vec[u]) {       if (v == p || vis[v]) continue;       Add(v, u);     }   }   void Rem(int u, int p) {     cnt[frq[col[u]]--]--;     for (auto v : vec[u]) {       if (v == p || vis[v]) continue;       Rem(v, u);     }   }   void DFS(int u, int p, bool first) {     int mx = -1, id = -1;     for (auto v : vec[u]) {       if (v == p) continue;       if (siz[v] > mx) mx = siz[v], id = v;     }     for (auto v : vec[u]) {       if (v == p || v == id) continue;       DFS(v, u, 1);     }     if (id != -1) DFS(id, u, 0), vis[id] = 1;     Add(u, p);     for (auto x : qry[u]) Res[x.second] = cnt[x.first];     if (id != -1) vis[id] = 0;     if (first) Rem(u, p);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> col[i];     int m = n - 1;     while (m--) {       int u, v;       cin >> u >> v;       vec[u].push_back(v);       vec[v].push_back(u);     }     dfs(1, 1);     for (int i = 1; i <= q; i++) {       int v, k;       cin >> v >> k;       qry[v].push_back(make_pair(k, i));     }     DFS(1, 1, 0);     for (int i = 1; i <= q; i++) cout << Res[i] <<   n ;     return 0;   }   