func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 100002;   map<int, int> cnt[MAX];   vector<int> adj[MAX];   long long ans[MAX];   int color[MAX];   int max_el[MAX];   void dfs(int node, int par) {     cnt[node][color[node]] = true;     max_el[node] = 1;     ans[node] = color[node];     for (int i = 0; i < adj[node].size(); i++) {       int child = adj[node][i];       if (child != par) {         dfs(child, node);         if (cnt[node].size() < cnt[child].size()) {           swap(cnt[node], cnt[child]);           max_el[node] = max_el[child];           ans[node] = ans[child];         }         for (pair<int, int> p : cnt[child]) {           cnt[node][p.first] += p.second;           if (cnt[node][p.first] == max_el[node])             ans[node] += p.first;           else if (cnt[node][p.first] > max_el[node]) {             max_el[node] = cnt[node][p.first];             ans[node] = p.first;           }         }       }     }   }   int main() {     int n, u0, v0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> color[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> u0 >> v0;       adj[u0].push_back(v0);       adj[v0].push_back(u0);     }     dfs(1, 0);     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }   