6.3每日一题题解

Game On Leaves

涉及知识点:

  • 思维/博弈

solution:

  • 首先我们要知道无根树的概念(就是任何一个节点都能当做根),然后仔细审题
  • 接下来你会发现,无论如何变化,最终和X 有关系的只是,最后两个与X相连的节点,
  • 设置 第一个节点为x1 ,第二个为x2。那么当取走x1的是Ashish,那么获胜的是Ayush,否则相反。
  • 所以只需要判断(n-2)的奇偶就可以了
  • 特别要关心当n为1的时候Ayush可以直接获胜

std:

#include <bits/stdc++.h>

using namespace std;
const int N = 20;

int n,wight;
int ans=0x3f3f3f3f;
int root[N],car[N];



int main()
{
    int t,cnt =0 ;
    int   n,m,k;
    cin >>t ;
    while(t--){
            cin >>n>> m;
            memset(root,0,sizeof(root));
            for(int i=1;i<n;i++){
                int u,v ;cin >>u >> v;
             root[u]++;
             root[v]++ ;
            }
            if(root[m]>1&&(n-2)%2==1)cout<<"Ashish"<<endl;
            else cout<<"Ayush"<<endl;
    }

}
posted @ 2020-06-03 08:53  QFNU-ACM  阅读(163)  评论(0编辑  收藏  举报