311323: CF1970C3. Game on Tree (Hard)

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

Description

C3. Game on Tree (Hard)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

This is the hard version of the problem. The only difference in this version is the constraint on $t$.

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$ ($1 \leq t \leq n$), 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$ lines, each line being either "Ron" or "Hermione".

ExamplesInput
5 2
1 2
1 3
3 4
3 5
1 2
Output
Ron
Ron
Input
6 3
1 2
2 3
1 4
4 5
4 6
1 4 6
Output
Hermione
Ron
Hermione

Output

题目大意:
这是一个困难版本的题目。在这个版本中,唯一的不同是对t的限制。罗恩和赫敏在一棵有n个节点的树上玩一个游戏,这些节点最初都是不活跃的。游戏由t轮组成,每一轮都是从恰好一个节点上的石头开始,这个节点被认为是激活的。一步操作包括挑选一个带有石头的节点的未激活邻居,并将石头移动到那里(从而激活这个邻居)。罗恩先走,之后他轮流和赫敏走,直到没有有效的移动为止。不能进行移动的玩家输掉这一轮。如果两位玩家都发挥最佳,谁会赢得每一轮比赛?

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

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

输出:
输出由t行组成,每行是“Ron”或“Hermione”,表示在该轮中获胜的玩家。题目大意: 这是一个困难版本的题目。在这个版本中,唯一的不同是对t的限制。罗恩和赫敏在一棵有n个节点的树上玩一个游戏,这些节点最初都是不活跃的。游戏由t轮组成,每一轮都是从恰好一个节点上的石头开始,这个节点被认为是激活的。一步操作包括挑选一个带有石头的节点的未激活邻居,并将石头移动到那里(从而激活这个邻居)。罗恩先走,之后他轮流和赫敏走,直到没有有效的移动为止。不能进行移动的玩家输掉这一轮。如果两位玩家都发挥最佳,谁会赢得每一轮比赛? 注意,所有轮次都在同一棵树上进行;只有起始节点会改变。此外,在每一轮之后,所有活跃的节点都被认为是非活跃的。 输入输出数据格式: 输入: 第一行包含两个整数n(2≤n≤2×10^5),t(1≤t≤n),分别是树中的节点数和轮数。 接下来的n-1行,每行包含两个整数1≤u,v≤n,对应树的一条边。 接下来的一行包含t个整数1≤u1,…,ut≤n,对应石头最初放置的节点。 输出: 输出由t行组成,每行是“Ron”或“Hermione”,表示在该轮中获胜的玩家。

加入题单

上一题 下一题 算法标签: