QOJ.ac

QOJ

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

#1824. Special Cycle

统计

자기 루프나 다중 간선이 없는 단순 무방향 그래프가 주어진다. 일부 간선은 Special로 표시되어 있다.

당신의 과제는 단순 사이클을 찾는 것이다. 이때 모든 Special 간선에 대하여, 해당 간선이 사이클에 포함되거나, 아니면 그 양 끝점 중 어느 것도 사이클에 닿지 않아야 한다. 사이클은 정점을 중복해서 방문할 수 없다. 임의의 해를 출력하거나, 존재하지 않는 경우 보고하라.

입력

첫 번째 줄에는 세 정수 $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.