题目链接:Problem - 1363C - Codeforces
题意:
多组数据(t≤10)
给定 n(n≤1000) 个节点的无根树。两名选手轮流操作,Ayush先手,每次可以选择一个叶节点并删除它以及所有和它相连的边。叶节点指度数不超过1的节点。删除节点 x的选手胜利。如果先手胜,输出 Ayush
,否则输出 Ashish
。
题解:
我们判断特殊情况n等于1时,只能是先手赢。
当n大于1时:
第一种情况:如果x本身就是叶子节点,那一定是先手赢。
第二种情况:如果不是叶子节点,我们把它看作根节点,最后赢的情况就是还剩两个点,其中一个是x,那么我们只要看n的奇偶性就可以了,如果n是偶数,(n-2)/2轮下来刚好拿完n-2个点,下一次拿就是先手拿,先手肯定拿x来获得胜利,也就是说当n等于偶数是先手必胜。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<map>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const ll mm = 1e3 + 60;
int a[mm];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n, x;
cin >> n >> x;
memset(a, 0, sizeof(a));
for (int i = 1; i <= n - 1; i++)
{
int u, v;
cin >> u >> v;
a[u]++;
a[v]++;
}
if (n == 1 || a[x] == 1 || n % 2 == 0) cout << "Ayush\n";
else cout << "Ashish\n";
}
return 0;
}