N. 环路 II

    Type: Default 1000ms 256MiB

环路 II

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目背景

翻译自 CSES-1678 题。

题目描述

Byteland 有 nn 个城市和 mm 条航班连接连接它们。你的任务是设计一个环路,要求从一个城市出发,经过一个或更多的其他城市,最后返回到起始城市。路线上每个中间城市必须是不同的。

输入格式

第一行包含两个整数 nnmm:分别表示城市的数量和航班的数量。城市编号为 1,2,,n1,2,…,n

接下来的 mm 行,每行包含两个整数 aabb:表示存在一条从城市 aa 和城市 bb 的单向航班。

输出格式

首先输出一个整数 kk:表示环路上经过的城市数。然后输出这 kk 个城市的编号,按照它们被访问的顺序输出。你可以输出任何一个有效的环路方案。

如果没有环路,输出 IMPOSSIBLE

样例

4 5
1 3
2 1
2 4
3 2
3 4
4
2 1 3 2

说明/提示

1n1051 \le n \le 10^5

1m21051\le m \le 2 \cdot 10^5

1a,bn1\le a,b \le n

CSES4 图论

Not Claimed
Status
Done
Problem
36
Open Since
2025-5-21 0:00
Deadline
2025-5-31 23:59
Extension
24 hour(s)