QOJ.ac

QOJ

実行時間制限: 4 s メモリ制限: 512 MB 満点: 100

#3550. 蹄与脑

統計

给定一个包含 $N$ 个顶点和 $M$ 条边的有向图($2 \leq N \leq 10^5$,$1 \leq M \leq 2 \cdot 10^5$),Farmer John 的奶牛们喜欢玩一个双人游戏。

在图中两个不同的节点上各放置一个棋子。每一轮,其中一名玩家(称为“大脑”)选择一个必须移动的棋子,另一名玩家(称为“蹄子”)选择该棋子沿哪条出边移动。两个棋子永远不能位于同一个节点上。如果蹄子在某一时刻无法进行有效的移动,则大脑获胜。如果游戏无限进行下去,则蹄子获胜。

给定 $Q$ 次询问($1 \leq Q \leq 10^5$),每次询问给出两个棋子的起始节点。对于每次询问,输出获胜的玩家。

输入格式

第一行包含 $N$ 和 $M$。

接下来的 $M$ 行,每行包含两个整数 $a$ 和 $b$,表示一条从 $a$ 到 $b$ 的有向边。

图中不包含自环或重边。

下一行包含 $Q$。

最后 $Q$ 行,每行包含两个整数 $x$ 和 $y$,满足 $1\le x,y\le N$ 且 $x\neq y$,表示两个棋子的起始节点。

输出格式

一个长度为 $Q$ 的字符串,其中每个字符表示获胜者:'B' 代表大脑获胜,'H' 代表蹄子获胜。

注意:本题的时间限制为 4 秒,是默认限制的两倍。

样例

样例输入 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

说明

大脑可以通过选择节点 5 赢得第一场游戏;此时蹄子没有有效的移动方式。

大脑可以通过选择节点 4 然后选择节点 7 赢得最后一场游戏;此时蹄子没有有效的移动方式。

蹄子赢得了其余的游戏。

子任务

  • 测试点 2-3 满足 $N\le 100$,$M\le 200$。
  • 测试点 4-9 满足 $N\le 5000$。
  • 测试点 10-21 无额外限制。

题目来源:Danny Mittal

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.