C. Game On Leaves(贪心结论)

, \color{red}看起来像博弈论,其实就是个结论贪心

1 0 ( 0 , ) 首先当特殊点入度为1或0时(没错还有0,这个很坑)

一定是先手直接可以除掉这个点

, 1 否则,当特殊点入度大于1,因为这是一棵树

使 0 , 一定要把树的所有边摘掉后才会使特殊点的入度为0,也就是摘掉这个点

( n 1 ) % 2 = = 1 , , 所以此时当(n-1)\%2==1,先手赢,否则后手赢

#include <bits/stdc++.h>
using namespace std;
const int maxn=20009;
int in[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,x;
		cin>>n>>x;
		memset(in,0,sizeof(in));
		for(int i=1;i<n;i++)
		{
			int l,r;
			cin>>l>>r;
			in[l]++,in[r]++;
		}
		if(in[x]==1||in[x]==0)	cout<<"Ayush"<<endl;
		else if((n-1)%2==1)	cout<<"Ayush"<<endl;
		else	cout<<"Ashish"<<endl;
	}
}

猜你喜欢

转载自blog.csdn.net/jziwjxjd/article/details/106464007