QOJ.ac

QOJ

時間限制: 12 s 記憶體限制: 1024 MB 總分: 100

#1824. 特殊環

统计

給定一個沒有自環或重邊的簡單無向圖。其中一些邊被標記為 Special。

你的任務是找到一個簡單環,使得對於每一條 Special 邊,該邊要麼屬於這個環,要麼其兩個端點都不在環上。環中不允許重複頂點。請輸出任意一個符合條件的解,若不存在則輸出 -1。

輸入格式

第一行包含三個整數 $n$ ($2 \le n \le 150$)、$m$ ($1 \le m \le \frac{n(n-1)}{2}$) 和 $k$ ($1 \le k \le m$),其中 $n$ 是圖中的節點數,$m$ 是邊數,$k$ 是 Special 邊的數量。節點編號為 $1$ 到 $n$。

接下來 $m$ 行,每行包含兩個整數 $a$ 和 $b$ ($1 \le a < b \le n$),表示節點 $a$ 和 $b$ 之間的一條無向邊。所有邊皆不相同。前 $k$ 條邊為 Special 邊。

輸出格式

若找到環,第一行輸出一個整數,表示該環的長度。隨後的行依序輸出環上的頂點,每行一個。若不存在這樣的環,則直接輸出 -1。

範例

範例輸入 1

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

範例輸出 1

8
1
4
5
6
7
8
3
2

範例輸入 2

4 6 3
1 2
1 3
1 4
2 3
3 4
2 4

範例輸出 2

-1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#600Editorial Open集训队作业 解题报告 by 陈翔乐Qingyu2026-01-18 16:21:19 Download

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.