#include #include using namespace std; //ifstream f("wow.in"); #define LE 100666 #include #define pb push_back #define f cin int fap[LE],lap[LE],up[20][LE]; bool viz[LE]; int lev[LE],K,lmax; vector H[LE]; void dfs(int nod) { int N=H[nod].size(),i; viz[nod]=true; fap[nod]=++K; for(i=0; i=fap[RAD]&&fap[nod_check]<=lap[RAD]) return true; return false; } int lca(int nod1,int nod2) { if (lev[nod1]=0; --i) if (up[i][nod1]!=up[i][nod2]) nod1=up[i][nod1],nod2=up[i][nod2]; int res=up[0][nod1]; return res; } int main() { int n,m,i,l; f>>n>>m; for(i=1; i>xx>>yy; H[xx].pb(yy); H[yy].pb(xx); } dfs(1); up[1][0]=1; for(l=1; (1<>typ; if (typ==1) { f>>CEO; continue; } if (typ==2) { f>>xx>>yy; int LC=lca(xx,yy); if (xx==CEO||yy==CEO) { cout<<-1; continue; } if (inside(LC,CEO)==false) { if (LC==xx||LC==yy) { cout<<-1<<'\n'; continue; } cout<