func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > G[500005];   int sz[500005];   vector<int> *vec[500005];   int cnt[(1 << 23) + 5];   int lazy[500005];   int len[500005];   int res[500005];   void get_ready(int u, int par, int mask, int hh) {     sz[u] = 1;     len[u] = hh;     lazy[u] = mask;     for (auto v : G[u])       if (v.first != par)         get_ready(v.first, u, mask ^ v.second, hh + 1), sz[u] += sz[v.first];   }   void DFS(int u, int par, int keep, int mask) {     int node = -1, mx = 0, xr = 0;     for (auto x : G[u]) {       int v = x.first;       if (par != v and sz[v] > mx) {         mx = sz[v], node = v, xr = x.second;       }     }     for (auto x : G[u]) {       int v = x.first;       if (v != par and v != node) DFS(v, u, 0, x.second);     }     if (node != -1) {       DFS(node, u, 1, xr);       vec[u] = vec[node];       res[u] = max(res[u], res[node]);     } else       vec[u] = new vector<int>;     for (int i = 1; i <= (1 << 22); i <<= 1) {       res[u] = max(res[u], cnt[lazy[u] ^ i] - len[u]);     }     res[u] = max(res[u], cnt[lazy[u]] - len[u]);     cnt[lazy[u]] = max(cnt[lazy[u]], len[u]);     vec[u]->push_back(u);     for (auto x : G[u]) {       int v = x.first;       if (v != par and v != node) {         res[u] = max(res[u], res[v]);         for (auto vv : *vec[v]) {           for (int i = 1; i <= (1 << 22); i <<= 1) {             res[u] = max(res[u], len[vv] + cnt[lazy[vv] ^ i] - 2 * len[u]);           }           res[u] = max(res[u], len[vv] + cnt[lazy[vv]] - 2 * len[u]);         }         for (auto vv : *vec[v]) {           int temp = lazy[vv];           cnt[temp] = max(cnt[temp], len[vv]);           vec[u]->push_back(vv);         }         vec[v]->clear();       }     }     if (!keep) {       for (auto v : *vec[u]) cnt[lazy[v]] = -1000000000;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     for (int i = 0; i < (1 << 23) + 5; i++) cnt[i] = -1000000000;     int N;     cin >> N;     for (int i = 2; i <= N; i++) {       string ch;       int p;       cin >> p >> ch;       G[p].push_back({i, 1 << (ch[0] -  a )});       G[i].push_back({p, 1 << (ch[0] -  a )});     }     get_ready(1, -1, 0, 0);     DFS(1, -1, 1, 0);     for (int i = 1; i <= N; i++) cout << res[i] <<    ;   }   