codeforces#P1970C3. Game on Tree (Hard)
Game on Tree (Hard)
Description
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.
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.
The output consists of $t$ lines, each line being either "Ron" or "Hermione".
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".
5 2
1 2
1 3
3 4
3 5
1 2
6 3
1 2
2 3
1 4
4 5
4 6
1 4 6
Ron
Ron
Hermione
Ron
Hermione