题目链接:https://vjudge.net/contest/396831#problem/C
题解:给你一个连通无向图,可以选择去除某个点,与他相邻的边也会去掉。判断两个人如果选择最优算法的话,谁会赢。当x相邻的点的个数小于等于1时,直接先下的人会赢。
当x相邻的点的个数大于1时初始的可以画为这样。
最后会变成这个样子:
当遇到这种情况时,谁先下谁输,所以只需要判断之前下的点的个数。即n-3个点的奇偶性。当为奇数时先下的赢;偶数时后下的赢
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int T;
int n,x;
scanf("%d",&T);
while(T--)
{
int degree=0,u,v;
scanf("%d%d",&n,&x);
for(int i=1;i<n;i++)
{
scanf("%d%d",&u,&v);
if(u==x||v==x)
degree++;
}
if(degree<=1)
printf("Ayush\n");
else
{
if((n-3)%2==1)
printf("Ayush\n");
else
printf("Ashish\n");
}
}
return 0;
}