首页 > 其他 > 详细

Codeforces Round #646 (Div. 2) C. Game On Leaves(树上博弈)

时间:2020-06-01 11:49:34      阅读:45      评论:0      收藏:0      [点我收藏+]

题目链接:https://codeforces.com/contest/1363/problem/C

题意

有一棵 $n$ 个结点的树,每次只能取叶子结点,判断谁能最先取到结点 $x$ 。

题解

除非结点 $x$ 一开始就为叶子结点,否则二人一定会取到只剩 $3$ 个结点,且中间结点为 $x$ 的情况。

所以,判断结点 $x$ 是否为叶子结点,否则再判断 $n - 3$ 的奇偶性即可。

代码

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, x; cin >> n >> x;
    int degree_x = 0;    
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        degree_x += (u == x) or (v == x);
    }
    if (degree_x <= 1)
        cout << "Ayush" << "\n";
    else
        cout << ((n - 3) % 2 == 0 ? "Ashish" : "Ayush") << "\n";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

 

Codeforces Round #646 (Div. 2) C. Game On Leaves(树上博弈)

原文:https://www.cnblogs.com/Kanoon/p/13023900.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!