Logo
(追記) (追記ここまで)

24972번 - Hoof and Brain 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB276564218.341%

문제

Given a directed graph with $N$ vertices and $M$ edges (2ドル \leq N \leq 10^5,ドル 1ドル \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 $Q$ queries (1ドル \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 $N$ and $M$.

The next $M$ lines each contain two integers $a$ and $b,ドル denoting an edge from $a$ to $b$.

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

The next line contains $Q$.

The final $Q$ lines each contain two integers $x$ and $y$ satisfying 1ドル\le x,y\le N$ and $x\neq y,ドル indicating the starting nodes of the tokens.

출력

A string of length $Q,ドル 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

힌트

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.

출처

Olympiad > USA Computing Olympiad > 2021-2022 Season > USACO 2022 US Open Contest > Platinum 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /