QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#13466. 湯姆與傑利

统计

給定一張包含 $n$ 個頂點和 $m$ 條邊的 無向連通圖,Tom 和 Jerry 在圖上進行了 $q$ 次追逐遊戲。

在第 $i$ 次遊戲中,Tom 一開始位於頂點 $a_i$,而 Jerry 一開始位於頂點 $b_i$(雙方任何時候都知道自己和對方的位置),追逐規則如下:

  • Jerry 和 Tom 交替行動,Jerry 先行動。
  • Jerry 每次行動可以通過無向圖中的 任意多條邊(可以選擇不移動),但是在移動過程中不能經過 Tom 當前所在的結點,否則就會被抓住。
  • Tom 每次行動只能通過無向圖中的 至多一條邊(可以選擇不移動)。
  • 如果 Tom 在一次行動後到達了 Jerry 的位置,那麼 Tom 勝利。

Tom 盡量想要勝利,而 Jerry 會盡量阻止 Tom 勝利。

現在你需要對於每一局遊戲,求出 Tom 是否一定能在有限次行動內獲勝。

輸入格式

第 $1$ 行:三個整數 $n,m,q$,分別表示無向連通圖的點數,邊數以及遊戲的次數。

接下來 $m$ 行:每行兩個整數 $x,y$,描述圖中的一條無向邊。

接下來 $q$ 行:每行兩個整數 $a,b$,表示一局遊戲中雙方的初始位置。

輸出格式

共 $q$ 行:對於每局遊戲,如果 Tom 可以在有限個回合內獲勝則輸出 Yes,否則輸出 No

範例

範例輸入 1

8 10 3
1 2
2 3
3 4
4 1
6 4
5 6
6 7
8 7
8 5
8 6
6 4
4 5
5 7

範例輸出 1

No
Yes
No

說明

第一組詢問中,$a_1=6,\ b_1=4$,則 Jerry 先走到 $2$ 處,此後每一回合,若 Tom 行動完後與 Jerry 相鄰,Jerry 只需要移動到環 $[1,2,3,4]$ 中與 Tom 不相鄰的那個點,可保證 Tom 不勝。

第二組詢問中,$a_2=4,\ b_2=5$,無論 Jerry 如何行動,Tom 只需走到 $6$ 處,此後 Jerry 可能在 $\{5,7,8\}$,無論如何 Tom 都可以一步追到。

第三組詢問中,$a_3=5,\ b_3=7$,則 Jerry 按照第一組詢問中的策略即可使得 Tom 無法獲勝。

子任務

本題採用捆綁測試。

對於 $100\%$ 的資料,$1\leq n,m,q\leq 10^5,\ \ 1\leq x,y,a,b\leq n$,$a_i\ne b_i$。

保證給出的無向圖連通,且不含重邊和自環。

$\text{Subtask 1}\ (10\%)$: $n,m,q\leq 10$。

$\text{Subtask 2}\ (16\%)$: $n,m,q\leq 100$。

$\text{Subtask 3}\ (24\%)$: $n,m,q\leq 1000$。

$\text{Subtask 4}\ (16\%)$: $m=n$。

$\text{Subtask 5}\ (34\%)$: 無特殊限制。

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.