#include #include #include #include #include #include #include using namespace std; int N, M; char A[200002]; vector V[200002]; int qn1[100002], qn2[100002], qs; int tat[200002]; int num[200002][26], niv[200002], T[18][200002]; int in[200002], out[200002]; bool S[200002]; bool is_str(int x, int y) { return in[x] <= in[y] && out[x] >= out[y]; } void Dfs(int x) { S[x] = true; ++num[x][A[x] - 'a']; for (int i = 1; i < 18; ++i) T[i][x] = T[i - 1][T[i - 1][x]]; in[x] = ++in[0]; for (auto it = V[x].begin(); it != V[x].end(); ++it) if (!S[*it]) { for (int i = 0; i < 26; ++i) num[*it][i] = num[x][i]; niv[*it] = niv[x] + 1; tat[*it] = x; T[0][*it] = x; Dfs(*it); } out[x] = ++out[0]; } int main() { cin.sync_with_stdio(false); cin >> N >> M; cin >> (A + 1); for (int i = 1, nod1, nod2; i <= N - 1; ++i) { cin >> nod1 >> nod2; V[nod1].push_back(nod2); V[nod2].push_back(nod1); } for (int i = 1; i <= M; ++i) { int type; cin >> type; if (type == 1) { ++qs; cin >> qn1[qs] >> qn2[qs]; } else { int nod; char col; cin >> nod >> col; ++N; A[N] = col; V[nod].push_back(N); V[N].push_back(nod); } } T[0][1] = 1; Dfs(1); for (int i = 1; i <= qs; ++i) { int nod1 = qn1[i], nod2 = qn2[i], LCA = 0; if (is_str(nod1, nod2)) LCA = nod1; else if (is_str(nod2, nod1)) LCA = nod2; else { LCA = nod1; for (int j = 17; j >= 0; --j) if (!is_str(T[j][LCA], nod2)) LCA = T[j][LCA]; LCA = T[0][LCA]; } int result = 0; for (int j = 0; j < 26; ++j) if ((num[nod1][j] + num[nod2][j] - num[LCA][j] - num[tat[LCA]][j]) % 2 == 1) ++result; cout << result << '\n'; } }