#include #include using namespace std; //ifstream f("wow.in"); #include #define LE 200666 #define x first #define y second #define mp make_pair #define pb push_back #define f cin int rmq[20][LE]; int lev[LE],ch[LE][30]; bool viz[LE]; pair Qs[LE]; vector H[LE]; int C[LE],lmax; void dfs(int nod) { int N=H[nod].size(),i; viz[nod]=true; ++ch[nod][C[nod]]; for(i=0; ilev[nod2]) swap(nod1,nod2); int D=lev[nod2]-lev[nod1],i; for(i=lmax; i>=0; --i) if (D&(1<=0; --i) if (rmq[i][nod1]!=rmq[i][nod2]) nod1=rmq[i][nod1],nod2=rmq[i][nod2]; return rmq[0][nod1]; } string str; int R[666]; int main() { int n,m,i,k=0,l=0; f>>n>>m; f.get(); f>>str; for(i=0; i>xx>>yy; H[xx].pb(yy); H[yy].pb(xx); } for(i=1; i<=m; ++i) { int xx,yy,typ; char cc; f>>typ; if (typ==1) { f>>xx>>yy; Qs[++k]=mp(xx,yy); } if (typ==2) { f>>xx>>cc; ++n; cc-='a'; C[n]=cc; H[xx].pb(n); H[n].pb(xx); } } dfs(1); for(l=1; (1<