Problem:
Score : 500 points

Problem Statement

You are given a connected undirected simple graph, which has N vertices and M edges.
The vertices are numbered 1 through N, and the edges are numbered 1 through M.
Edge i connects vertices A_i and B_i.
Your task is to find a path that satisfies the following conditions:

The path traverses two or more vertices.

The path does not traverse the same vertex more than once.

A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.

It can be proved that such a path always exists.
Also, if there are more than one solution, any of them will be accepted.

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i < B_i \leq N

The given graph is connected and simple (that is, for every pair of vertices, there is at most one edge that directly connects them).

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Find one path that satisfies the conditions, and print it in the following format.
In the first line, print the count of the vertices contained in the path.
In the second line, print a space-separated list of the indices of the vertices, in order of appearance in the path.

Sample Input 1

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

Sample Output 1

4
2 3 1 4

There are two vertices directly connected to vertex 2: vertices 3 and 4.
There are also two vertices directly connected to vertex 4: vertices 1 and 2.
Hence, the path 2 → 3 → 1 → 4 satisfies the conditions.

Sample Input 2

7 8
1 2
2 3
3 4
4 5
5 6
6 7
3 5
2 6

Sample Output 2

7
1 2 3 4 5 6 7

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
class Program
{
    static IO io = new IO();

    static List<int>[] xPointCanMove;

    static void Main(string[] args)
    {
        //入力
        io.ReadSplit();
        int N = io.Int();
        int M = io.Int();
        int[] A = new int[M];
        int[] B = new int[M];
        for (int i = 0; i < M; ++i)
        {
            io.ReadSplit();
            A[i] = io.Int();
            B[i] = io.Int();
        }

        //計算
        xPointCanMove = new List<int>[N + 1];
        for (int i = 0; i < N + 1; ++i)
        {
            xPointCanMove[i] = new List<int>();
        }
        for (int i = 0; i < M; ++i)
        {
            xPointCanMove[A[i]].Add(B[i]);
            xPointCanMove[B[i]].Add(A[i]);
        }
        List<int> xPath = GetPath();

        //出力
        io.Write(xPath.Count.ToString());
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        for (int i = 0; i < xPath.Count - 1; ++i)
        {
            sb.Append(xPath[i].ToString());
            sb.Append(" ");
        }
        sb.Append(xPath[xPath.Count - 1].ToString());
        io.Write(sb.ToString());
    }
    static List<int> GetPath()
    {
        List<int> xPath = new List<int>();
        for (int i = 1; i <= xPointCanMove.Length; ++i)
        {
            xPath = GetPath(i, xPath);
            if (xPath.Count > 1)
            {
                return xPath;
            }
        }
        return xPath;
    }
    static List<int> GetPath(int xPoint, List<int> xPaths)
    {
        if (xPaths.Contains(xPoint))
        {
            return null;
        }
        xPaths.Add(xPoint);
        if (IsAllValueContains(xPaths, xPointCanMove[xPaths[0]]) && (IsAllValueContains(xPaths, xPointCanMove[xPaths[xPaths.Count - 1]])))
        {
            return xPaths;
        }
        foreach (int xNewPoint in xPointCanMove[xPoint])
        {
            List<int> xNewPaths = GetPath(xNewPoint, xPaths);
            if (xNewPaths != null)
            {
                return xNewPaths;
            }
        }
        xPaths.RemoveAt(xPaths.Count - 1);
        return null;
    }

    static bool IsAllValueContains(List<int> xPaths, List<int> xPoints)
    {
        foreach (int i in xPoints)
        {
            if (!xPaths.Contains(i)) { return false; }
        }
        return true;
    }
}

class IO
{
    private string[] input;
    private int index;
    public void Read()
    {
        input = new string[1];
        input[0] = Console.ReadLine();
        index = -1;
    }
    public void ReadSplit()
    {
        input = Console.ReadLine().Split(' ');
        index = -1;
    }
    public string String()
    {
        index += 1;
        return input[index];
    }
    public string[] String(int count)
    {
        index += 1;
        string[] rv = new string[count];
        Array.Copy(input, index, rv, 0, count);
        return rv;
    }
    public int Int()
    {
        index += 1;
        return int.Parse(input[index]);
    }
    public int[] Int(int count)
    {
        index += 1;
        int[] rv = new int[count];
        for (int i = 0; i < count; ++i)
        {
            rv[i] = int.Parse(input[index + i]);
        }
        return rv;
    }
    public long Long()
    {
        index += 1;
        return long.Parse(input[index]);
    }
    public long[] Long(int count)
    {
        index += 1;
        long[] rv = new long[count];
        for (int i = 0; i < count; ++i)
        {
            rv[i] = long.Parse(input[index + i]);
        }
        return rv;
    }
    public void Write(string str)
    {
        Console.WriteLine(str);
    }
}