#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int INF = 0x3f3f3f3f; const double EPS = 1e-11; const double PI = 3.141592653589793; const int MAX_N = 300005; const long long LLINF = 99999999999999999LL; const int SIGMA = 26; int N, M; int D[MAX_N][20], S[MAX_N][20][SIGMA], lv[MAX_N], F[MAX_N], a[SIGMA]; vector < int > v[MAX_N], Level[MAX_N]; char val[MAX_N]; bool vis[MAX_N]; void DFS(int x) { vis[x] = 1; Level[lv[x]].push_back(x); for(int i = 0; i < (int) v[x].size(); ++i) { int y = v[x][i]; if(vis[y]) continue; lv[y] = lv[x] + 1; F[y] = x; DFS(y); } } int main() { /* #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif */ cin >> N >> M; for(int i = 1; i <= N; ++i) cin >> val[i]; for(int i = 1; i < N; ++i) { int x, y; scanf("%d %d", &x, &y); v[x].push_back(y); v[y].push_back(x); } lv[1] = 1; DFS(1); for(int i = 1; i <= N; ++i) { for(int j = 0; j < (int) Level[i].size(); ++i) { int x = Level[i][j]; D[x][0] = F[x]; S[x][0][val[F[x]] - 'a']++; for(int k = 1; (1 << k) <= i; ++k) { D[x][k] = D[D[x][k - 1]][k - 1]; for(int h = 0; h < SIGMA; ++h) S[x][k][h] = S[x][k - 1][h] + S[D[x][k - 1]][k - 1][h]; } } } for(int q = 1; q <= M; ++q) { int t, x, y; char c; scanf("%d", &t); if(t == 1) { scanf("%d %d", &x, &y); for(int i = 0; i < SIGMA; ++i) a[i] = 0; if(lv[x] < lv[y]) swap(x, y); int i = 0, j = 0; for(int k = 1; k <= 19; ++k) { if((1 << k) <= lv[x]) i = k; if((1 << k) <= lv[y]) j = k; } int lca = 0, x1 = x, y1 = y; for(int k = i; k >= 0; --k) if(lv[x] - (1 << k) >= lv[y]) x = D[x][k]; if(x == y) lca = x; else { for(int k = j; k >= 0; --k) if(D[x][k] && D[x][k] != D[y][k]) { x = D[x][k]; y = D[y][k]; } lca = D[x][0]; } // x = x1; y = y1; while(x != lca) { i = 0; for(int k = 1; k <= 19; ++k) if(lv[D[x][k]] >= lv[lca]) i = k; for(int h = 0; h < SIGMA; ++h) a[h] += S[x][i][h]; x = D[x][i]; } while(y != lca) { i = 0; for(int k = 1; k <= 19; ++k) if(lv[D[y][k]] >= lv[lca]) i = k; for(int h = 0; h < SIGMA; ++h) a[h] += S[y][i][h]; y = D[y][i]; } ++a[val[x1] - 'a']; ++a[val[y1] - 'a']; --a[val[lca] - 'a']; int ans = 0; for(int i = 0; i < SIGMA; ++i) if(a[i] % 2) ++ans; printf("%d\n", ans); } else { scanf("%d %c", &x, &c); ++N; y = N; lv[y] = lv[x] + 1; F[y] = x; val[y] = c; swap(x, y); D[x][0] = F[x]; S[x][0][val[F[x]] - 'a']++; for(int k = 1; (1 << k) <= lv[x]; ++k) { D[x][k] = D[D[x][k - 1]][k - 1]; for(int h = 0; h < SIGMA; ++h) S[x][k][h] = S[x][k - 1][h] + S[D[x][k - 1]][k - 1][h]; } } } return 0; }