func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > q[500005];   int n, m, tot, nms, ans[500005], dep[500005], ms[500005], sz[500005],       t[500005][30], a[500005], hd[500005], to[500005], nxt[500005];   char ch[500005];   int read() {     int x = 0, fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * fl;   }   void add(int x, int y) {     tot++;     to[tot] = y;     nxt[tot] = hd[x];     hd[x] = tot;     return;   }   void dfs(int x, int f) {     sz[x] = 1;     int mx = 0;     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f) continue;       dep[y] = dep[x] + 1, dfs(y, x);       sz[x] += sz[y];       if (sz[y] > mx) mx = sz[y], ms[x] = y;     }     return;   }   void calc(int x, int f, int o) {     t[dep[x]][a[x]] += o;     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f || y == nms) continue;       calc(y, x, o);     }     return;   }   void dsu(int x, int f, int o) {     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f || y == ms[x]) continue;       dsu(y, x, -1);     }     if (ms[x]) dsu(ms[x], x, 1), nms = ms[x];     calc(x, f, 1), nms = 0;     for (int p = 0; p < (int)q[x].size(); p++) {       int d = q[x][p].first, id = q[x][p].second, cnt = 0;       for (int i = 1; i <= 26; i++) cnt += (t[d][i] & 1);       ans[id] = (cnt <= 1);     }     if (o == -1) calc(x, f, -1);     return;   }   int main() {     n = read(), m = read();     for (int i = 2; i <= n; i++) {       int x = read();       add(x, i);     }     scanf( %s , ch + 1);     for (int i = 1; i <= n; i++) a[i] = ch[i] -  a  + 1;     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       q[x].push_back(make_pair(y, i));     }     dep[1] = 1, dfs(1, 0), dsu(1, 0, -1);     for (int i = 1; i <= m; i++) printf( %s n , ans[i] ?  Yes  :  No );     return 0;   }   