CF1363C Game On Leaves题解

本文介绍了CF1363C Game On Leaves的题解,这是一个关于两人在树上进行的博弈问题。游戏规则是双方轮流选择一个叶子节点,目标是先达到特定编号x的一方获胜。关键在于理解,除非根节点的度为1,否则必须取完所有子节点才能到达根。因此,只需考虑子节点的数量即可判断胜负。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值