QOJ.ac

QOJ

حد الوقت: 3.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#14683. 捕捉怪獸

الإحصائيات

一隻史前怪獸透過 Peter 博士的時光機來到了地球。你需要幫助 Peter 博士抓住牠。

怪獸藏在一個有 $n$ 個頂點和 $m$ 條邊的森林中。這裡,森林是一個無環無向圖,可能由多棵樹組成。你可以透過執行以下操作來捕捉怪獸:

  • 首先,你選擇一個頂點 $x$ ($1 \le x \le n$)。
  • 然後,如果怪獸目前在頂點 $x$,牠就被抓住了。
  • 否則,怪獸仍未被抓住,在操作之後,牠可以移動到與目前頂點相鄰的任意頂點(頂點 $x$ 除外)。或者牠也可以選擇不移動,留在同一個頂點。

我們定義一個森林是美妙的,若且唯若存在一個有限的頂點序列 $a$,使得無論怪獸的初始位置如何以及牠如何移動,按照 $a$ 的順序選擇頂點執行操作,都能保證怪獸被抓住。

現在,你需要回答 Peter 博士的 $q$ 個問題。在每個問題中,他會給你一個區間 $[l, r]$ ($1 \le l \le r \le n$)。你需要告訴他,由編號在 $[l, r]$ 內的頂點導出的子森林(即僅保留這些頂點以及它們之間的邊所形成的圖)是否是美妙的。

輸入格式

第一行包含三個整數 $n$、$m$ 和 $q$ ($2 \le n \le 10^6$, $1 \le m \le n - 1$, $1 \le q \le 10^6$),其中 $n$ 是森林中的頂點數,$m$ 是森林中的邊數,$q$ 是詢問次數。

接下來的 $m$ 行,每行包含兩個整數 $u$ 和 $v$ ($1 \le u, v \le n$, $u \ne v$),表示森林中的一條邊。

接下來的 $q$ 行,每行包含兩個整數 $l$ 和 $r$ ($1 \le l \le r \le n$),表示一次詢問。

輸出格式

對於每次詢問,如果該子森林是美妙的,輸出一行「Yes」;否則,輸出一行「No」。

你可以輸出任意大小寫的答案(大寫或小寫)。例如,字串「yEs」、「yes」、「Yes」和「YES」都會被識別為肯定回答。

範例

輸入 1

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

輸出 1

Yes
Yes
No

輸入 2

100000 1 1
1 2
1 9999

輸出 2

Yes

說明

在第一個測試資料中:

  • 在第一次詢問中,對於子森林 $[1, 3]$,你可以設置 $a = [3, 1, 2]$。
  • 在第二次詢問中,對於子森林 $[2, 6]$,你可以設置 $a = [3, 4, 5, 2, 6]$。
  • 在第三次詢問中,對於子森林 $[1, 10]$,可以證明不存在有限的有效序列 $a$。

在第二個測試資料中:

  • 在唯一的一次詢問中,對於子森林 $[1, 9999]$,你可以設置 $a = [1, 2, \dots, 9999]$。

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.