311322: CF1970C2. Game on Tree (Medium)

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C2. Game on Tree (Medium)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

This is the medium version of the problem. The difference in this version is that $t=1$ and we work on trees.

Ron and Hermione are playing a game on a tree of $n$ nodes that are initially inactive. The game consists of $t$ rounds, each of which starts with a stone on exactly one node, which is considered as activated. A move consists of picking an inactive neighbor of the node with a stone on it and moving the stone there (thus activating this neighbor). Ron makes the first move, after which he alternates with Hermione until no valid move is available. The player that cannot make a move loses the round. If both players play optimally, who wins each round of this game?

Note that all the rounds are played with the same tree; only the starting node changes. Moreover, after each round, all active nodes are considered inactive again.

Input

The first line contains integers $n$ ($2 \leq n \leq 2\times 10^5$), $t$ ($t=1$), the number of nodes in the tree and the number of rounds, respectively.

The next $n-1$ lines contain two integers $1 \leq u, v \leq n$ each, corresponding to an edge of the tree.

The next line contains $t$ integers $1 \leq u_1 , \dots, u_t \leq n$, corresponding to the node where the stone is initially put.

Output

The output consists of $t=1$ line which is either "Ron" or "Hermione".

ExampleInput
5 1
1 2
1 3
3 4
3 5
1
Output
Ron

Output

题目大意:
这是一个关于在树上进行的游戏的题目。有n个节点的树,最初所有节点都是非激活状态。游戏分为t轮,每轮从树上的一个节点开始放置一个石头,这个节点就被认为是激活状态。每次移动包括选择一个带有石头节点的非激活邻居节点,并将石头移动到那里(从而激活这个邻居节点)。Ron先走,然后他和Hermione交替进行,直到没有有效的移动为止。无法进行移动的玩家输掉这一轮。如果两位玩家都进行最佳操作,谁会赢得每一轮游戏?

注意,所有轮次都在同一棵树上进行;只有起始节点会变化。此外,每轮之后,所有激活的节点都会再次被认为是非激活状态。

输入输出数据格式:
输入:
第一行包含两个整数n(2≤n≤2×10^5),t(t=1),分别是树中的节点数和轮数。
接下来的n-1行,每行包含两个整数1≤u,v≤n,对应树的一条边。
最后一行包含t个整数1≤u_1,…,u_t≤n,对应放置石头的起始节点。

输出:
输出包含t=1行,内容为“Ron”或“Hermione”,表示赢得该轮的玩家。

示例:
输入:
5 1
1 2
1 3
3 4
3 5
1

输出:
Ron题目大意: 这是一个关于在树上进行的游戏的题目。有n个节点的树,最初所有节点都是非激活状态。游戏分为t轮,每轮从树上的一个节点开始放置一个石头,这个节点就被认为是激活状态。每次移动包括选择一个带有石头节点的非激活邻居节点,并将石头移动到那里(从而激活这个邻居节点)。Ron先走,然后他和Hermione交替进行,直到没有有效的移动为止。无法进行移动的玩家输掉这一轮。如果两位玩家都进行最佳操作,谁会赢得每一轮游戏? 注意,所有轮次都在同一棵树上进行;只有起始节点会变化。此外,每轮之后,所有激活的节点都会再次被认为是非激活状态。 输入输出数据格式: 输入: 第一行包含两个整数n(2≤n≤2×10^5),t(t=1),分别是树中的节点数和轮数。 接下来的n-1行,每行包含两个整数1≤u,v≤n,对应树的一条边。 最后一行包含t个整数1≤u_1,…,u_t≤n,对应放置石头的起始节点。 输出: 输出包含t=1行,内容为“Ron”或“Hermione”,表示赢得该轮的玩家。 示例: 输入: 5 1 1 2 1 3 3 4 3 5 1 输出: Ron

加入题单

上一题 下一题 算法标签: