膜yzy神犇的题解
脑洞(我)好大(弱)啊根本想不到。。
#include<iostream>
#include<cstdio>
using namespace std;
int n,k,m,T,ans=1;
int f[2500005];
inline int read()
{
int a=0,f=1; char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
return a*f;
}
int find(int i)
{
return f[i]==i?i:f[i]=find(f[i]);
}
inline void calc(int a,int b,int c)
{
int x,y;
if (c==1)
{
if (a==1) x=b,y=T;
else if (a==n) x=(m-1)*m+b,y=T;
else x=(a-2)*m+b,y=(a-1)*m+b;
}
else
{
if (b==1) x=(a-1)*m+1,y=T;
else if (b==n) x=a*m,y=T;
else x=(a-1)*m+b-1,y=(a-1)*m+b;
}
int p=find(x),q=find(y);
if (p==q) ans=0;
else f[p]=q,ans=1;
}
int main()
{
n=read(); k=read(); m=n-1; T=m*m+1;
for (int i=1;i<=T;i++) f[i]=i;
for (int i=1;i<=k;i++)
{
char s[5];
int a1=read(),b1=read();
scanf("%s",s);
int c1=s[0]=='N'?1:2;
int a2=read(),b2=read();
scanf("%s",s);
int c2=s[0]=='N'?1:2;
if (ans) calc(a1,b1,c1);
else calc(a2,b2,c2);
puts(ans?"TAK":"NIE");
}
}