#define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include using namespace std; #define DMAX 100002 int n, m; string s; vector > > T; vector parent; void BFS(int root){ int i, chld; queue Q; Q.push(root); while (Q.size()){ root = Q.front(); Q.pop(); for ( i = T[root].second.size() - 1; i >= 0; i--){ chld = T[root].second[i]; parent[chld] = root; Q.push(chld); } } } string getpath(int x, int y){ string p; parent.insert(parent.begin(), 0, T.size() + 1); BFS(x); while (parent[y] != x){ p += T[y].first; y = parent[y]; } return p; } void solve(int x, int y){ int i, c = 0; string p = getpath(x, y); vector a(26); for (i = s.size() - 1; i >= 0; i--){ a[s[i] - 'a']++; } for ( i = 0; i < 26; i++){ if (a[i] % 2) c++; } cout << c << '\n'; } int main(){ int i, x, y; //freopen("test.in", "r", stdin); //freopen("test.out", "w", stdout); cin >> n >> m >> s; T.push_back({ 'c', {}}); for ( i = 0; i < n; i++) T.push_back({ s[i], {} }); for ( i = 1; i < n; i++){ cin >> x >> y; T[x].second.push_back(y); T[y].second.push_back(x); } for ( i = 0; i < m; i++){ cin >> x; if(x == 1){ cin >> x >> y; solve(x, y); } else{ cin >> x >> y; T.push_back({ (char)y - 'a', {} }); T[x].second.push_back(T.size()); T[T.size()].second.push_back(x); } } return 0; }