#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, u, a; void BFS(int root){ int i, chld; queue Q; u.insert(u.begin(), T.size() + 1, 0); Q.push(root); while (Q.size()){ root = Q.front(); Q.pop(); u[root] = 1; for ( i = T[root].second.size() - 1; i >= 0; i--){ chld = T[root].second[i]; if (!u[chld]){ parent[chld] = root; Q.push(chld); } } } u.clear(); } void getpath(int x, int y){ parent.insert(parent.begin(), T.size() + 1, 0); BFS(x); a[T[y].first - 'a']++; while (parent[y] != x){ y = parent[y]; a[T[y].first - 'a']++; } a[T[x].first - 'a']++; parent.clear(); } void solve(int x, int y){ int i, c = 0; string p; a.insert(a.begin(), 26, 0); getpath(x, y); for ( i = 0; i < 26; i++) if (a[i] % 2) c++; cout << c << '\n'; a.clear(); } int main(){ int i, x, y; char c; //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 >> c; T.push_back({ c, {} }); T[x].second.push_back(T.size() - 1); T[T.size() - 1].second.push_back(x); } } return 0; }