func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int size[maxn], dep[maxn], val[maxn], dfn[maxn], hson[maxn], ans[maxn],       rnk[maxn];   int cnt[(1 << 22) + 4];   struct EDGE {     int to, next;     char c;   } edge[maxn << 1];   int head[maxn], tot, num;   void addedge(int u, int v, char c) {     edge[++tot].next = head[u];     edge[tot].to = v;     edge[tot].c = c;     head[u] = tot;   }   void dfs(int now, int pre) {     size[now] = 1;     dep[now] = dep[pre] + 1;     dfn[now] = ++num;     rnk[num] = now;     for (int i = head[now]; i; i = edge[i].next) {       int to = edge[i].to;       if (to == pre) continue;       val[to] = val[now] ^ (1 << (edge[i].c -  a ));       dfs(to, now);       size[now] += size[to];       if (size[to] > size[hson[now]]) hson[now] = to;     }   }   void cal(int now) {     if (cnt[val[now]]) ans[now] = max(ans[now], cnt[val[now]] - dep[now]);     for (int i = 0; i < 22; ++i) {       if (cnt[val[now] ^ (1 << i)])         ans[now] = max(ans[now], cnt[val[now] ^ (1 << i)] - dep[now]);     }     cnt[val[now]] = max(cnt[val[now]], dep[now]);     for (int i = head[now]; i; i = edge[i].next) {       int to = edge[i].to;       if (dep[to] < dep[now] || to == hson[now]) continue;       for (int j = dfn[to]; j <= dfn[to] + size[to] - 1; ++j) {         int tmp = rnk[j];         if (cnt[val[tmp]])           ans[now] = max(ans[now], cnt[val[tmp]] + dep[tmp] - 2 * dep[now]);         for (int i = 0; i < 22; ++i) {           if (cnt[val[tmp] ^ (1 << i)])             ans[now] =                 max(ans[now], cnt[val[tmp] ^ (1 << i)] + dep[tmp] - 2 * dep[now]);         }       }       for (int j = dfn[to]; j <= dfn[to] + size[to] - 1; ++j) {         int tmp = rnk[j];         cnt[val[tmp]] = max(cnt[val[tmp]], dep[tmp]);       }     }   }   void dfs2(int now, bool heave) {     for (int i = head[now]; i; i = edge[i].next) {       int to = edge[i].to;       if (dep[to] < dep[now] || to == hson[now]) continue;       dfs2(to, 0);       ans[now] = max(ans[now], ans[to]);     }     if (hson[now]) dfs2(hson[now], 1), ans[now] = max(ans[now], ans[hson[now]]);     cal(now);     if (!heave)       for (int i = dfn[now]; i <= dfn[now] + size[now] - 1; ++i)         cnt[val[rnk[i]]] = 0;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 2; i <= n; ++i) {       int to;       char c;       scanf( %d %c , &to, &c);       addedge(i, to, c);       addedge(to, i, c);     }     dfs(1, 0);     dfs2(1, 0);     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }   