Game On Leaves CodeForces - 1363C(思維博弈)

題意:一顆n個節點的數,兩個人分別取葉節點,最後取到x節點的人獲勝。

題解:顯然,最後只有兩個節點即出現了必勝態,我們只考慮最後兩個節點前面n-2個節點的是誰最後到達的必勝態即可(就是n-2的奇偶性),注意n==1和x節點度數爲1的情況要特判。

AC代碼:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,x,du=0;
		cin>>n>>x;
		for(int i=1;i<=n-1;i++){
			int u,v;
			cin>>u>>v;
			if(u==x||v==x)du++;
		}
		if(du==1||n<2)cout<<"Ayush"<<endl;//注意考慮剩下2個節點的必勝態前提是剛開始就要有兩個節點 
		else{
			if((n-2)%2==0)cout<<"Ayush"<<endl;
			else cout<<"Ashish"<<endl;
		}
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章