eolymp
bolt
Try our new interface for solving problems
Problems

Article

Article

In the year \textbf{2048} sociologists got interested in the structure of the community of competitive programmers and as the result of their studies made the following observations. The news about the success of any contestant passes from any of his acquaintances to all his acquaintances (probably through other people). Two persons do not communicate unless they know each other and when they do, they only discuss people they both know, but not themselves. Additionally, looking at the acquaintances of any person, there are no triples among them where all three would be pairwise unacquainted. Now the community decided to pool their funds to pay the enormous license fee for an article describing a new algorithm that can multiply square matrices in \textbf{Θ(N^\{2.32768\})} time (where \textbf{N} is the size of the matrices). Unsurprisingly, the license agreement strictly forbids making copies of the article. Everyone wants to read the article, of course, but no one is willing to pass it on to someone they don't know. Also, they are busy people and don't want to manage the article after reading it. The only exception is Vasya: he's the holder of the article; he bought the copy with the pooled money and he will keep it after everyone has read it. But even he is only willing to collect it from the last reader for archiving, but not to run around carrying it from one reader to another. Find the maximal number of people who can read the article under the above conditions and the order in which they should pass the article among themselves for that to happen. All programmers are numbered by positive integer numbers and Vasya's number is \textbf{1}. \InputFile \includegraphics{file:///E:/2012-2013/ACM/BSU-2012/problems/article/statements/.html/english/cd713a842a2d74f0236dde57486c427aa9d7b08a.png} The first line contains two integers \textbf{N} and \textbf{M} (\textbf{3}  ≤  \textbf{N}  ≤  \textbf{1000}, \textbf{0}  ≤  \textbf{M}  ≤  \textbf{10 000}, \textbf{M} ≤ \textbf{N(N-1)/2}), the number of pro-gram-mers and number of pairs of acquainted programmers. Each of the next \textbf{M} lines contains exactly two integers \textbf{p_1} and \textbf{p_2} (\textbf{1}  ≤  \textbf{p_1}, \textbf{p_2} ≤ \textbf{N}, \textbf{p_1} ≠\textbf{ p2}), numbers of acquainted programmers. \OutputFile In the first line output integer \textbf{K}, the number of programmers who can read the article. In the next line output \textbf{K} different numbers, the order in which they can read it. This sequence should start with \textbf{1}, should not contain any number more than once, any two consecutive numbers should correspond to acquainted people and the last programmer should be acquainted with Vasya.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
3 3
1 2
1 3
2 3
Output example #1
3
1 3 2 
Source NEERC Western Subregional Contest 2012