A879 | Hoof and Brain--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交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.
$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.
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.****
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
输出 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted