1363C - Game On Leaves - CodeForces Solution


games trees *1600

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n, x = map(int, input().split())
    count = 0

    for i in range(n-1):
        u, v = map(int, input().split())
        if u == x or v == x:
            count +=1
            
    if n == 1 and x == 1:
        print("Ayush")

    elif count == 1:
        print("Ayush")

    elif n%2 == 0:
        print("Ayush")

    elif n%2 == 1:
        print("Ashish")

C++ Code:

#include <bits/stdc++.h>
using namespace std;
 
#define int               int64_t
#define rep(i,a,b)        for(int i = a; i < b; i++)
#define rrep(i,a,b)       for(int i = b; i >=a; i--)
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define emb               emplace_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)(x.size())
#define fr                first
#define sc                second
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define pii               pair<int,int>
#define vi                vector<int>
#define v2i               vector<vi>
#define vp                vector<pii>
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define cpar              __builtin_parity
#define sum(a,x)          accumulate(all(a),x)
#define lowb(a,x)         lower_bound(all(a),x) - a.begin()
#define uppb(a,x)         upper_bound(all(a),x) - a.begin()
#define maxpq             priority_queue<int>
#define minpq             priority_queue<int,vector<int>,greater<int>>
#define endl              "\n"
const int MOD = 1e9 + 7;
 
template<typename T,typename V> inline T amax(T &a,V b){if(b>a)a=b;return a;}
template<typename T,typename V> inline T amin(T &a,V b){if(b<a)a=b;return a;}
template <typename T> inline T gcd(T a, T b) {while (b != 0) swap(b, a %= b); return a;}
template <typename T> inline T inv(T i) {if (i == 1) return 1; return (MOD - ((MOD / i) * inv(MOD % i)) % MOD) % MOD;}
/*--------------------------------------------------------------------------*/
//Debug Area
 
#ifndef Ana
#define debug(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define debug(x);
#endif
 
template <typename T> void print(T t) {cerr << t;}
 
template <typename T, typename V> void print(pair <T, V> p);
template <typename T> void print(vector <T> v);
template <typename T> void print(set <T> v);
template <typename T, typename V> void print(map <T, V> v);
template <typename T> void print(multiset <T> v);
 
template <typename T, typename V> void print(pair <T, V> p) {cerr << "{"; print(p.fr); cerr << ","; print(p.sc); cerr << "}";}
template <typename T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <typename T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <typename T, typename V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
template <typename T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
 
/*--------------------------------------------------------------------------*/
 
const int INF = 1e18;
const int32_t M = 998244353;
 
 
const int N = 1e5 + 10;

const int mod =  998244353;
 
int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void solve(int test_cases)
{ 
     // cout<<"Case #"<<test_cases<<":"<<" ";
    int n,x;
    cin>>n>>x;
    --x;
    v2i adj(n);
    rep(i,0,n-1)
    {
        int u,v;
        cin>>u>>v;
        --u,--v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    if(sz(adj[x])<=1 || (n-1)&1 == 1)
    {
        cout<<"Ayush"<<endl;
    }
    else cout<<"Ashish"<<endl;
    return;
}

signed main()
{
   
   ios::sync_with_stdio(false);
   cin.tie(NULL);
 
   #ifdef SIEVE
    sieve();
   #endif
 
   #ifdef Ana
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
   #endif
   #ifndef Ana
     freopen("error.txt", "w", stderr);
   #endif
   
   int t = 1;
   cin>>t;
   int T = 1;
 
   while(t--)
   {
     solve(T);
     T++;
   }
 
   cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
   return 0;
}


Comments

Submit
0 Comments
More Questions

1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array
2090. K Radius Subarray Averages
2091. Removing Minimum and Maximum From Array
6. Zigzag Conversion
1612B - Special Permutation
1481. Least Number of Unique Integers after K Removals
1035. Uncrossed Lines
328. Odd Even Linked List
1219. Path with Maximum Gold
1268. Search Suggestions System
841. Keys and Rooms
152. Maximum Product Subarray
337. House Robber III
869. Reordered Power of 2
1593C - Save More Mice