#include<cstdio>
struct Node
{
int *leader;
int** his;
int id;
};
Node* no;
bool test(int a,int b)
{
return no[a].leader==no[b].leader;
}
int main()
{
int n,m,c,x,y,day=0;
bool ans;
scanf("%d %d",&n,&m);
no=new Node[n];
for(int i=0;i<n;i++)
{
no[i].id=i;
no[i].leader=&no[i].id;
no[i].his=new int*[m];
}
for(int i=0;i<m;i++)
{
day++;
scanf("%d",&c);
if(ans!=0)
c=c^ans;
switch(c)
{
case 0:
scanf("%d",&x);
if(ans!=0)
x=x^ans;
for(int i=0;i<n;i++)
{
no[i].leader=no[i].his[day];
}
break;
case 1:
case 2://x<y??
scanf("%d %d",&x,&y);
if(ans!=0)
{
x=x^ans;
y=y^ans;
}
x--;
y--;
if(c==1)
{
no[y].leader=no[x].leader;
}else
{
ans=test(x,y);
printf("%d\n",ans);
}
break;
}
for(int i=0;i<n;i++)
{
no[i].his[day]=no[i].leader;
}
}
return 0;
}
還是n*m的陣列太大了?