#581
Unrated
Hoof and Brain
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Given a directed graph with NN vertices and MM edges (2N1052 \leq N \leq 10^5, 1M21051 \leq M \leq 2 \cdot 10^5), 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 QQ queries (1Q1051 \leq Q \leq 10^5) indicating the starting nodes of the two tokens. For each query, output which player will win.

입력

The first line contains NN and MM.

The next MM lines each contain two integers aa and bb, denoting an edge from aa to bb.

The graph does not contain self-loops or multiple edges.

The next line contains QQ.

The final QQ lines each contain two integers xx and yy satisfying 1x,yN1\le x,y\le N and xyx\neq y, indicating the starting nodes of the tokens.

출력

A string of length QQ, where each character is B for the brain winning and H for the hoof winning.

예제 입력 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

예제 출력 1

BHHB

점수

Test cases 2-3 satisfy N100N\le 100, M200M\le 200.Test cases 4-9 satisfy N5000N\le 5000.Test cases 10-21 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.