Hoof and Brain
문제
Given a directed graph with vertices and edges (, ), Farmer John's cows like to play the following game with two players.Place two tokens on distinct nodes in the graph. Each turn, one player, the brain, will choose a token that must be moved along an outgoing edge. The other player, the hoof, will choose which edge to move the token along. The two tokens can never be on the same node. If at some point the hoof can't make a valid move, the brain wins. If the game continues indefinitely, the hoof wins.
You are given queries () indicating the starting nodes of the two tokens. For each query, output which player will win.
입력
The first line contains and .The next lines each contain two integers and , denoting an edge from to .
The graph does not contain self-loops or multiple edges.
The next line contains .
The final lines each contain two integers and satisfying and , indicating the starting nodes of the tokens.
출력
A string of length , where each character is B for the brain winning and H for the hoof winning.
힌트
The brain can win the first game by selecting node 5; then the hoof has no valid move.
The brain can win the last game by selecting node 4 and then node 7; then the hoof has no valid move.
The hoof wins the other games.
예제
예제 1
9 10 1 2 2 3 3 4 4 7 3 5 1 6 6 8 8 9 9 6 7 2 4 1 5 1 2 1 6 2 4
BHHB