Date:2022.01.02
题意:n个结点,每次选一个度<=1的点连带其一条边消掉,谁拿到点x谁胜利,"Ayush"先手, "Ashish"后手。
思路:除非先手第一次就能拿到目标点,否则二者持续给对方制造障碍,使x每次都在最后只剩两个节点时被选,判断节点奇偶即可。
代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
typedef long long LL;
LL t,n,m,k;
LL a[N];LL d[N];
//除非先手首次能遇到,其它情况都是两者互相阻碍
//直到剩两个节点,其中有一个是目标节点,因此目标节点必在倒数第二步被选,倒数第二个出手的赢
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>t;
while(t--)
{
memset(d,0,sizeof d);
cin>>n>>m;set<LL>s;
for(int i=1;i<=n-1;i++)
{
int x,y;cin>>x>>y;
d[x]++,d[y]++;
s.insert(x);s.insert(y);
}
if(d[m]==1||s.size()%2==0) cout<<"Ayush"<<endl;
else cout<<"Ashish"<<endl;
}
return 0;
}