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;
    }
  • 相关阅读:
    2020暑假项目-车辆派遣管理系统开发记录#8
    2020暑假项目-车辆派遣管理系统开发记录#7
    2020暑假项目-车辆派遣管理系统开发记录#6
    2020暑假项目-车辆派遣管理系统开发记录#5
    2020暑假项目-车辆派遣管理系统开发记录#4
    2020暑假项目-车辆派遣管理系统开发记录#3
    持续交付工具ThoughtWorks Go部署step by step
    mysql千万级大数据SQL查询优化
    分享MYSQL中的各种高可用技术(源自姜承尧大牛)
    我的MYSQL学习心得(十七) 复制
  • 原文地址:https://www.cnblogs.com/dealer/p/13028072.html
Copyright © 2011-2022 走看看