#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define dbg(x) (cout<<#x<<" = "<<(x)<<'\n') #ifdef HOME const string inputFile = "input.txt"; const string outputFile = "output.txt"; #else const string problemName = ""; const string inputFile = problemName + ".in"; const string outputFile = problemName + ".out"; #endif typedef long long int lld; typedef pair PII; typedef pair PIL; typedef pair PLI; typedef pair PLL; const int INF = (1LL << 31) - 1; const lld LINF = (1LL << 62) - 1; const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; const int MOD = (int)(1e9) + 7; const int NMAX = 200000 + 5; const int MMAX = 100000 + 5; const int KMAX = 100000 + 5; const int PMAX = 100000 + 5; const int LMAX = 100000 + 5; const int VMAX = 100000 + 5; int N, M; vector V[NMAX]; int lvl[NMAX]; int dad[20][NMAX]; int A[NMAX][30]; char S[NMAX]; void dfs(int x) { for(auto y : V[x]) if(!lvl[y]) { lvl[y] = lvl[x] + 1; dad[0][y] = x; for(int i = 0; i < 26; i++) A[y][i] = A[x][i] + (S[y] == ('a' + i)); dfs(y); } } void insert(int x, int c) { N++; V[N].push_back(x); V[x].push_back(N); dad[0][N] = x; lvl[N] = lvl[x] + 1; for(int i = 0; i < 26; i++) A[N][i] = A[x][i] + (c == ('a' + i)); for(int j = 1;; j++) { dad[j][N] = dad[j - 1][dad[j - 1][N]]; if(!dad[j][N]) break; } } int lca(int x, int y) { if(lvl[x] < lvl[y]) swap(x, y); if(lvl[x] > lvl[y]) { for(int j = 19; j >= 0; j--) if((lvl[x] - (1 << j)) >= lvl[y]) x = dad[j][x]; } for(int j = 19; j >= 0; j--) if(dad[j][x] != dad[j][y]) { x = dad[j][x]; y = dad[j][y]; } if(x == y) return x; else if(dad[0][x] == dad[0][y]) return dad[0][x]; else while(1); } int main() { int i, j, t, x, y, z, p, sol; char c; #ifdef HOME freopen(inputFile.c_str(), "r", stdin); freopen(outputFile.c_str(), "w", stdout); #endif scanf("%d %d\n", &N, &M); scanf("%s\n", S + 1); for(i = 1; i <= N - 1; i++) { scanf("%d %d\n", &x, &y); V[x].push_back(y); V[y].push_back(x); } A[1][S[1] - 'a']++; lvl[1] = 1; dfs(1); for(i = 1; i <= N; i++) for(j = 1;; j++) { dad[j][i] = dad[j - 1][dad[j - 1][i]]; if(!dad[j][i]) break; } while(M--) { scanf("%d ", &t); if(t == 1) { scanf("%d %d\n", &x, &y); z = lca(x, y); sol = 0; for(i = 0; i < 26; i++) { p = A[x][i] - A[dad[0][z]][i]; p += A[y][i] - A[dad[0][z]][i]; p -= A[z][i] - A[dad[0][z]][i]; sol += p % 2; } printf("%d\n", sol); continue; } if(t == 2) { scanf("%d %c\n", &x, &c); insert(x, c); continue; } } return 0; }