0
点赞
收藏
分享

微信扫一扫

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;
}
}
}

 

举报

相关推荐

0 条评论