zoukankan      html  css  js  c++  java
  • C. Game On Leaves

    Ayush and Ashish play a game on an unrooted tree consisting of nn nodes numbered 11 to nn. Players make the following move in turns:

    • Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpoints. A leaf node is a node with degree less than or equal to 11.

    A tree is a connected undirected graph without cycles.

    There is a special node numbered xx. The player who removes this node wins the game.

    Ayush moves first. Determine the winner of the game if each player plays optimally.

    Input

    The first line of the input contains a single integer t(1t10)(1≤t≤10) — the number of testcases. The description of the test cases follows.

    The first line of each testcase contains two integers nn and x(1n1000,1xn)(1≤n≤1000,1≤x≤n) — the number of nodes in the tree and the special node respectively.

    Each of the next n1n−1 lines contain two integers uu, v(1u,vn, uv)(1≤u,v≤n, u≠v), meaning that there is an edge between nodes uu and vv in the tree.

    Output

    For every test case, if Ayush wins the game, print "Ayush", otherwise print "Ashish" (without quotes).

    Examples
    input
    Copy
    1
    3 1
    2 1
    3 1
    
    output
    Copy
    Ashish
    
    input
    Copy
    1
    3 2
    1 2
    1 3
    
    output
    Copy
    Ayush
    
    Note

    For the 11st test case, Ayush can only remove node 22 or 33, after which node 11 becomes a leaf node and Ashish can remove it in his turn.

    For the 22nd test case, Ayush can remove node 22 in the first move itself.

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const double eps = 1e-6;
    const int mod = 998244353;
    const int N = 2500 + 5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    int main()
    {
        int T;
        cin >> T;
        while(T--)
        {
            int n, x,c=0;
            cin >> n >> x;
            vector<vector<int>> a(n + 1);
            rep(i, 1, n - 1)
            {
                int u, v;
                cin >> u >> v;
                if (u == x || v == x)
                    c++;
            }
            if(c<=1)
                cout << "Ayush" << endl;
            else
            {
                if (n % 2)
                    cout << "Ashish" << endl;
                else
                    cout <<  "Ayush"<< endl;
            }
    
        }
        return 0;
    }
  • 相关阅读:
    记录第一次阿里云服务器部署java web工程的经历
    常用网站……
    根据ID获取CEdit的句柄实例
    (转)MFC中获得各个类的指针/句柄 ID的总结
    (转)DoDataExchange执行时机
    深入浅出Visual_C动态链接库(Dll)编程(宋宝华)----整理(word)
    (转)MFC的一些宏的整理 (DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE)
    Socket 学习入门
    (转) 新的开始之Win7、CentOS 6.4 双系统 硬盘安装
    WIN7下使用VC2010调试uCOS-II 2.91
  • 原文地址:https://www.cnblogs.com/dealer/p/13028072.html
Copyright © 2011-2022 走看看