数组开太小会time error。
用cin cout也会time error。
/*
qq:1239198605
ctgu_yyf
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int par[100005*2];
int rank[100005*2];
int n,m;
void init(int n)
{
for(int i=1;i<=n;i++)
{
par[i]=i;
rank[i]=0;
}
}
int find(int x)
{
if(par[x]==x)
return x;
else
return par[x]=find(par[x]);
}
void unite(int x,int y)
{
x=find(x);
y=find(y);
if(x==y)
return ;
if(rank[x]<rank[y])
par[x]=y;
else
{
par[y]=x;
if(rank[x]==rank[y])
rank[x]++;
}
}
bool same(int x,int y)
{
return find(x)==find(y);
}
int main()
{
//ios::sync_with_stdio(false);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
init(n*2);
char c[2];
int u,v;
for(int i=0;i<m;i++)
{
scanf("%s",c);
scanf("%d%d",&u,&v);
if(c[0]=='A')
{
if(same(u,v)||same(u+n,v+n))
cout<<"In the same gang."<<endl;
else if(same(u,v+n)||same(u+n,v))
cout<<"In different gangs."<<endl;
else
cout<<"Not sure yet."<<endl;
}
if(c[0]=='D')
{
unite(u,v+n);
unite(v,u+n);
}
}
}
return 0;
}