Gym102361K MUV LUV UNLIMITED

Link
求出所有叶子所在链的链长(即从该叶子节点到达第一个度数不为\(1\)的祖先需要经过的边数),若所有链长均为偶数那么先手必败,否则先手必胜。

#include<cstdio>
#include<cctype>
#include<cstring>
const int N=1000007;
int fa[N],deg[N];
int read(){int x=0,c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
int check(int x){int l=0;for(int p=x;p&&deg[p]<=1;p=fa[p],++l);return l&1;}
int main()
{
    for(int T=read(),n,f;T;--T)
    {
	n=read(),f=0,memset(deg,0,(n+1)*4);
	for(int i=2;i<=n;++i) ++deg[fa[i]=read()];
	for(int i=1;i<=n;++i) if(!deg[i]&&check(i)) {f=1;break;}
	puts(f? "Takeru":"Meiya");
    }
}

猜你喜欢

转载自www.cnblogs.com/cjoierShiina-Mashiro/p/12642053.html