QOJ.ac

QOJ

Límite de tiempo: 5 s Límite de memoria: 2048 MB Puntuación total: 100

#8686. 動物園管理

Estadísticas

管理動物園時,有時你會想把動物移到不同的圍欄。你可能發現,斑馬會喜歡企鵝目前住的較寬敞圍欄,而企鵝可能想搬到無尾熊目前住的較寒冷圍欄;無尾熊則會搬到一個可以放滿尤加利葉的空圍欄。因此,你會先移動無尾熊,騰出較寒冷的圍欄,再把企鵝移到那裡,最後移動斑馬。

移動動物的方法是使用連接圍欄的特殊隧道——你不希望動物走到外面,一方面是怕牠們受驚,另一方面是怕牠們逃跑而受傷。

problem_8686_a2a053ee36bb78fadb0dd8509481feee.png

動物園的照片,裡面有一隻駱駝、一隻驢子和(一部分)一隻山羊。

不幸的是,你最近接收了更多動物,所有圍欄現在都滿了,使得移動動物困難許多。例如,假設無尾熊要搬到原本斑馬的圍欄——你就無法先移動任何一群動物。於是你學會了讓動物同時移動:斑馬、無尾熊和企鵝同時進入不同的隧道,並同時抵達新的圍欄,這樣牠們就永遠不會相遇。注意,你不能用這種方式直接交換兩個相連圍欄中的動物(因為牠們會在隧道中相遇並受到驚嚇)。

因此,你現在有一道難題。你有一份圍欄清單,每個圍欄裡有一種動物;其中一些圍欄由隧道相連。你可以任意多次選擇一些動物,將每一群移到由隧道相鄰的圍欄,但該圍欄中的動物也必須在同一次操作中移動,而且同一次操作中每條隧道至多使用一次。你也有理想的動物配置。能否透過一系列操作達成它呢?

輸入格式

輸入的第一行包含兩個整數 $n$($1 \le n \le 4 \cdot 10^5$)及 $m$($0 \le m \le 4 \cdot 10^5$),分別表示圍欄及隧道的數量。接下來有 $n$ 行,第 $i$ 行包含兩個整數 $b_i$($1 \le b_i \le 10^6$)及 $e_i$($1 \le e \le 10^6$),表示圍欄 $i$ 最初的動物種類,以及你希望在所有操作結束後圍欄 $i$ 裡的動物種類。可以假設 $e_1, \ldots, e_n$ 是 $b_1, \ldots, b_n$ 的一個排列。

接下來 $m$ 行描述隧道。每行包含兩個整數 $x$ 和 $y$($1 \le x < y \le n$),表示圍欄 $x$ 與 $y$ 之間有一條雙向隧道。任何兩個圍欄之間至多有一條隧道。

輸出格式

若能移動動物,使每個圍欄都包含期望的動物種類,輸出 possible。否則,輸出 impossible。

範例

輸入格式 1

3 3
1 4
4 7
7 1
1 2
2 3
1 3

輸出格式 1

possible

輸入格式 2

2 1
1 2
2 1
1 2

輸出格式 2

impossible

輸入格式 3

5 6
10 40
20 30
30 50
40 20
50 10
1 2
2 3
1 3
3 4
3 5
4 5

輸出格式 3

possible

輸入格式 4

4 4
10 10
10 20
20 10
20 20
1 2
2 3
3 4
1 4

輸出格式 4

impossible

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.