zoukankan      html  css  js  c++  java
  • Codeforces Round #646 (Div. 2) 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 tt (1≤t≤10)(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 xx (1≤n≤1000,1≤xn)(1≤n≤1000,1≤x≤n) — the number of nodes in the tree and the special node respectively.

    Each of the next n−1n−1 lines contain two integers uu, vv (1≤u,vnuv)(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

    理解错了题意简直硬伤

    首先判断如果x这个点的度为1或者0的话一定是先手必胜,因为x也是叶子节点,直接取走就好了(没想到这点卡了半天==)

    其次两个人一定是都尽可能不让x的度变成1,因为这样下一个人就能直接把拿走了,因此最后一定是这样的情况:A——X——B X夹在中间。现在还剩下3个点,此时拿走A或者B的人就必输,因此判断一下n-3的奇偶性(或者n的也行)即可。

    #include <bits/stdc++.h>
    using namespace std;
    int deg[1005];
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            memset(deg,0,sizeof(deg));
            int i,n,x;
            cin>>n>>x;
            for(i=1;i<=n-1;i++)
            {
                int u,v;
                cin>>u>>v;
                deg[u]++,deg[v]++;
            }
            if(deg[x]<=1)
            {
                cout<<"Ayush"<<endl;
                continue;
            }
            if(n&1)
            {
                cout<<"Ashish"<<endl;    
            }
            else
            {
                cout<<"Ayush"<<endl;
            }
        }
     } 
  • 相关阅读:
    操作系统进程通信
    操作系统进程调度
    java中的变量
    java移位运算符
    String, StringBuffer, StringBuilder 的区别
    多线程相关问题汇总
    java内存管理与GC机制(二)
    java内存管理与GC机制(一)
    进程与线程的理解
    Liferay7使用maven引入第三方jar包
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13027360.html
Copyright © 2011-2022 走看看