CF1363C Game On Leaves题解

CF1363C Game On Leaves

题意:有两个人进行树上博弈,规则是每个人都取一个叶子节点,先取到x编号的人赢,问谁赢。
解法:其实炒鸡简单!当时想了半天,各种树上最短路,要注意到的是,每个人都只能取叶子节点,那么把要取得编号当作根的话,会发现除非根的度是1,不然的话要取到根,必须把子节点都取掉,直接看这些点够取多少次就行。
代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
    
    
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') {
    
     if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') {
    
     res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int ne[8][2] = {
    
    1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 1010;
const LL Mod = 1e9+7;
const int M = 1e6+10;
int in[N];
int main() {
    
    
  int T; scanf("%d", &T);
  int n, x, u, v;
  while(T--) {
    
    
    memset(in, 0, sizeof in);
    scanf("%d%d", &n, &x);
    _for(1, n, i) {
    
    
      scanf("%d %d", &u, &v);
      ++in[u]; ++in[v];
    }
    if(n == 1 || in[x] == 1 || n%2 == 0) puts("Ayush");
    else puts("Ashish");
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43408978/article/details/108897713
今日推荐