题目描述
Problem Description
Translated from CEOI2015 Day1 T1「Potemkin cycle」
Brief Description $\,$ Given an undirected graph with $|V|=N$ and $|E|=R$. Find a simple path such that the set of vertices in the path, denoted as $V'$, satisfies: $|V'| \ge 4$, and the induced subgraph of $V'$ contains only the path itself (i.e., a chain).
Duke Potemkin's territory can be regarded as an undirected graph. He requires you to find a route, represented by a sequence of nodes $s_1,\dots,s_m$, that meets the following criteria:
- $m \geq 4$
- Each node visited is distinct (i.e., for all $i \neq j$, $s_i \neq s_j$)
- For $i = 1,\dots,m - 1$, $s_i$ is directly connected to $s_{i + 1}$, and $s_m$ is directly connected to $s_1$.
- The nodes in the sequence do not have any other edges (i.e., for all $i < j$ such that $j \neq i + 1$ and $i \neq 1$ or $j \neq m$, there is no edge between nodes $s_i$ and $s_j$).
Input Format
The first line contains two non-negative integers $N$ and $R$ $(0 \leq N \leq 1,000, 0 \leq R \leq 100,000)$, representing the number of nodes and the number of roads, respectively.
The next $R$ lines each contain two distinct positive integers $a_i$ and $b_i$ $(1 \leq a_i, b_i \leq N)$, indicating that there is an edge between nodes $a_i$ and $b_i$.
It is guaranteed that there is at most one edge between any two nodes.
Output Format
Output the sequence $s_1,\dots,s_m$ that meets the problem's description (if there are multiple solutions, output any one). If there is no solution, output no.
Sample Input and Output
Sample Input #1
5 6
1 2
1 3
2 3
4 3
5 2
4 5
Sample Output #1
2 3 4 5
Sample Input #2
4 5
1 2
2 3
3 4
4 1
1 3
Sample Output #2
no
Notes
The upper limits for $N$ and $R$ are as follows:
| Data Point | 1-3 | 4-5 | 6-7 | 8-10 |
|---|---|---|---|---|
| $N$ Upper Limit | 10 | 100 | 300 | 1,000 |
| $R$ Upper Limit | 45 | 1,000 | 20,000 | 100,000 |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分