RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0529

Hoof and Brain

Diamond III 다이아몬드 III
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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.

Problem credits: Danny Mittal

제약

SCORING

  • Test cases 2-3 satisfy \(N\le 100\), \(M\le 200\).
  • Test cases 4-9 satisfy \(N\le 5000\).
  • Test cases 10-21 satisfy no additional constraints.

Problem credits: Danny Mittal

입력 형식

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.

*Note: the time limit for this problem is 4s, twice the default.*

예제 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
설명

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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2021-2022 > US Open > Platinum

태그

평가 및 의견

Hoof and Brain

개요
출제자 난이도 Diamond III 다이아몬드 III 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Hoof and Brain

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8