func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxc = 22;   const int maxn = (int)5e5;   int tin[maxn], tout[maxn], _t = 0, ver[maxn], n;   vector<int> g[maxn];   int deep[maxn], maxh[1 << maxc];   unsigned mask[maxn];   int sz[maxn], ans[maxn];   unsigned char s[maxn];   int dfs_size(int v, unsigned m) {     mask[v] = m;     sz[v] = 1;     ver[tin[v] = _t++] = v;     for (auto u : g[v]) {       deep[u] = 1 + deep[v];       sz[v] += dfs_size(u, m ^ (1U << s[u]));     }     tout[v] = _t;     return sz[v];   }   const int INF = (int)1e9;   int calc(int u, int v) {     int res = maxh[mask[u]] + deep[u] - 2 * deep[v];     for (int i = 0; i < maxc; ++i) {       int m = mask[u] ^ (1U << i);       res = max(res, maxh[m] + deep[u] - 2 * deep[v]);     }     return res;   }   void dfs(int v, bool flag) {     int heavy = -1;     for (auto u : g[v])       if (heavy == -1 || sz[heavy] < sz[u]) heavy = u;     for (auto u : g[v])       if (heavy != u) {         dfs(u, 0);         ans[v] = max(ans[v], ans[u]);       }     if (heavy != -1) {       dfs(heavy, 1);       ans[v] = max(ans[v], ans[heavy]);     }     for (auto u : g[v])       if (u != heavy) {         for (int t = tin[u]; t < tout[u]; ++t)           ans[v] = max(ans[v], calc(ver[t], v));         for (int t = tin[u]; t < tout[u]; ++t)           maxh[mask[ver[t]]] = max(maxh[mask[ver[t]]], deep[ver[t]]);       }     ans[v] = max(ans[v], calc(v, v));     maxh[mask[v]] = max(maxh[mask[v]], deep[v]);     if (!flag)       for (int t = tin[v]; t < tout[v]; ++t) maxh[mask[ver[t]]] = -INF;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; ++i) {       int v;       cin >> v >> s[i];       g[v - 1].push_back(i);       s[i] -=  a ;     }     dfs_size(0, 0);     fill(maxh, maxh + (1 << maxc), -INF);     dfs(0, 1);     for (int i = 0; i < n; ++i) cout << ans[i] <<    ;     return 0;   }   