1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cmath>
5 #include<algorithm>
6 #include<ext/rope>
7 using namespace std;
8 using namespace __gnu_cxx;
9 const int MAXN=2000050;
10 const int maxn=0x7fffffff;
11 void read(int &n)
12 {
13 char c=‘+‘;int x=0;bool flag=0;
14 while(c<‘0‘||c>‘9‘){c=getchar();if(c==‘-‘)flag=1;}
15 while(c>=‘0‘&&c<=‘9‘){x=x*10+(c-48);c=getchar();}
16 flag==1?n=-x:n=x;
17 }
18
19 rope<int> *rp[MAXN];
20 int a[MAXN];
21 int n,m,how,x,y,lastans;
22 int find(int i,int x)
23 {
24 if(rp[i]->at(x)==x) return x;
25 int f=find(i,rp[i]->at(x));
26 if(f==rp[i]->at(x)) return f;
27 rp[i]->replace(x,f);
28 return f;
29 }
30 void merge(int i,int x,int y)
31 {
32 x=find(i,x),y=find(i,y);
33 if(x!=y) rp[i]->replace(y,x);
34 }
35 int main()
36 {
37 int n,m;
38 read(n);read(m);
39 for(int i=1;i<=n;i++) a[i]=i;
40 rp[0]=new rope<int> (a,a+n+1);
41 for(int i=1;i<=m;i++)
42 {
43 rp[i]=new rope<int> (*rp[i-1]);
44 int how;read(how);
45 if(how==1)
46 {
47 read(x);read(y);
48 merge(i,x^lastans,y^lastans);
49 }
50 else if(how==2)
51 {
52 read(x);
53 rp[i]=rp[x^lastans];
54 }
55 else if(how==3)
56 {
57 read(x);read(y);
58 printf("%d\n",lastans=(find(i,x^lastans)==find(i,y^lastans)));
59 }
60 }
61 return 0;
62 }