luogu#P4797. [CEOI 2015] 波将金的路径 (Day1)

[CEOI 2015] 波将金的路径 (Day1)

Problem Description

Translated from CEOI2015 Day1 T1 “Potemkin cycle”.

Brief statement Given an undirected graph with V=N|V|=N and E=R|E|=R. Find a simple cycle. Let the vertex set of this cycle be VV'. It must satisfy: V4|V'| \ge 4, and the subgraph induced by VV' contains only this cycle itself.


Duke Potemkin’s territory can be viewed as an undirected graph. He asks you to find a route whose visited vertices are represented by a sequence s1,,sms_1,\dots,s_m, and it must satisfy the following:

  • m4m \geq 4.

  • All visited vertices are pairwise distinct (i.e., for all iji \neq j, sisjs_i \neq s_j).

  • For i=1,,m1i = 1,\dots,m - 1, sis_i is directly connected to si+1s_{i + 1}, and sms_m is directly connected to s1s_1.

  • There are no other edges among the vertices in the sequence (i.e., for all i<ji < j such that ji+1j \neq i + 1 and either i1i \neq 1 or jmj \neq m, there is no edge between sis_i and sjs_j).

Input Format

The first line contains two non-negative integers NN and RR (0N1 000,0R100 000)(0 \leq N \leq 1\ 000, 0 \leq R \leq 100\ 000), representing the number of vertices and the number of roads (edges), respectively.

The next RR lines each contain two distinct positive integers aia_i and bib_i (1ai,biN)(1 \leq a_i,b_i \leq N), indicating that there is an edge between vertices aia_i and bib_i.

It is guaranteed that there is at most one edge between any pair of vertices.

Output Format

Output the sequence s1,,sms_1,\dots,s_m that satisfies the requirements in the description (if there are multiple solutions, output any one). If there is no solution, output no.

5 6
1 2
1 3
2 3
4 3
5 2
4 5
2 3 4 5
4 5
1 2
2 3
3 4
4 1
1 3
no

Hint

The upper limits of NN and RR are shown in the table below:

Test case group 131-3 454-5 676-7 8108-10
Upper limit of NN 1010 100100 300300 1 0001\ 000
Upper limit of RR 4545 1 0001\ 000 20 00020\ 000 100 000100\ 000

Translated by ChatGPT 5