QOJ.ac

QOJ

Time Limit: 12 s Memory Limit: 1024 MB Total points: 100

#1824. Special Cycle

Statistics

自己ループや多重辺を持たない単純な無向グラフが与えられます。一部の辺は「Special」としてマークされています。

あなたのタスクは、各Specialな辺について、その辺がサイクルに含まれるか、あるいはその辺のどちらの端点もサイクルに接していないような単純サイクルを見つけることです。サイクルは頂点を重複してはなりません。解を1つ出力するか、存在しない場合はその旨を報告してください。

入力

入力の最初の行には、3つの整数 $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$ 行の各行には、2つの整数 $a$ と $b$ ($1 \le a < b \le n$) が含まれ、ノード $a$ と $b$ の間の無向辺を表します。すべての辺は異なります。最初の $k$ 個の辺がSpecialな辺です。

出力

見つかったサイクルの長さを1行目に出力してください。続く行に、サイクル上の頂点を順に、1行に1つずつ出力してください。そのようなサイクルが存在しない場合は、単に $-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.