func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) s = s * 10 + ch -  0 , ch = getchar();     return s;   }   inline char getch() {     char ch = getchar();     while (!islower(ch)) ch = getchar();     return ch;   }   const int N = 20005;   int n, m, u, v, x, y, c1, c2, ans;   int dfn[N], dep[N], fa[N], dfn_t, pos[N], ab[N];   int tag[N], len[N], type[N];   char s[N], t[N], fw[N];   vector<pair<int, char> > G[N];   void dfs(int u, int f) {     dep[u] = dep[f] + 1, fa[u] = f;     dfn[u] = ++dfn_t, pos[dfn_t] = u;     ab[dfn[u]] = dfn[f];     for (auto v : G[u]) {       if (v.first == f) continue;       fw[v.first] = v.second;       dfs(v.first, u);     }   }   int main() {     n = read(), m = read();     for (int i = 1; i < n; i++) {       u = read(), v = read();       char c = getch();       G[u].emplace_back(v, c);       G[v].emplace_back(u, c);     }     dfs(1, 0);     for (int T = 1; T <= m; T++) {       memset(s + 1, 0, n * sizeof(char));       u = x = read(), v = y = read();       c1 = c2 = 0;       while (u != v)         dep[u] > dep[v] ? (s[++c1] = fw[u], u = fa[u])                         : (t[++c2] = fw[v], v = fa[v]);       for (; c2;) s[++c1] = t[c2--];       type[dfn[x]] = len[dfn[x]] = 0, tag[dfn[x]] = T;       ans = 0;       for (int i = dfn[x]; ab[i];) {         tag[ab[i]] = T, len[ab[i]] = len[i] + 1;         type[ab[i]] =             (type[i]                  ? type[i]                  : ((fw[pos[i]] > s[len[ab[i]]]) - (fw[pos[i]] < s[len[ab[i]]])));         i = ab[i];         if (type[i] == -1 || (!type[i] && len[i] < c1)) ++ans;       }       for (int i = 2; i <= n; i++) {         if (tag[i] != T) {           len[i] = len[ab[i]] + 1;           type[i] = (type[ab[i]]                          ? type[ab[i]]                          : ((fw[pos[i]] > s[len[i]]) - (fw[pos[i]] < s[len[i]])));           if (type[i] == -1 || (!type[i] && len[i] < c1)) ++ans;         }       }       printf( %d n , ans);     }     return 0;   }   