Problem:
Score: 400 points

Problem Statement

There is a cave.

The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.

It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.

Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.

If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.

Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq M \leq 2 \times 10^5

1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)

A_i \neq B_i\ (1 \leq i \leq M)

One can travel between any two rooms by traversing passages.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

If there is no way to place signposts satisfying the objective, print No.

Otherwise, print N lines. The first line should contain Yes, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i.

Sample Input 1

4 4
1 2
2 3
3 4
4 2

Sample Output 1

Yes
1
2
2

If we place the signposts as described in the sample output, the following happens:

Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \to 1. This is the minimum number of passages possible.

Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \to 2 \to 1. This is the minimum number of passages possible.

Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \to 2 \to 1. This is the minimum number of passages possible.

Thus, the objective is satisfied.

Sample Input 2

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

Sample Output 2

Yes
6
5
5
1
1

If there are multiple solutions, any of them will be accepted.

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Text;

namespace ForATCODER
{
  public  class Program
    {
        ///template
        ///
        /// String[] s = Console.ReadLine().Split(' ');
        ///   long[] nk =  s2larray(Console.ReadLine().Split(' '));
        ///  
        static int[] res;
        static int now = 0;
        static int result(int d,int dept,int from)
        {
            if (TreeNode<int>.StopOp) return 0;
            if (dept == 0) return 0;
       RESULT("visited:"+d+" dept:"+dept+" from:"+from,true);
            res[d] = from;
            return 0;
        }
      static  List<int> goals = new List<int>();
        public static void Main(string[] args)
        {
            goals.Add(1);   
             int[] nm = s2iarray(Console.ReadLine().Split(" "));
          //    TreeNode<int> tn = new TreeNode<int>(1);
            TreeNode<int>[] tn_stack = new TreeNode<int>[nm[0]+1];
            tn_stack[1] = new TreeNode<int>(1);
            //build tree
            for (int i = 0; i < nm[1]; i++)
              {
                  int[] ab = s2iarray(Console.ReadLine().Split(" "));

                if (tn_stack[ab[0]] == null)
                {
                    tn_stack[ab[0]] = new TreeNode<int>(ab[0]);
                }
                    if (tn_stack[ab[1]] == null)
                    {
                        tn_stack[ab[1]] = new TreeNode<int>(ab[1]);
                    }
                if (ab[0] == 1) goals.Add(ab[1]);
                if (ab[1] == 1) goals.Add(ab[0]);
                tn_stack[ab[0]].AddChildRelative(tn_stack[ab[1]]);
                    tn_stack[ab[1]].AddChildRelative(tn_stack[ab[0]]);
                

              }
            //      tn.AddChild(1);
            TreeNode<int> root = tn_stack[1];
            res = new int[nm[0]+1];
            TreeNode<int>.BFS(tn_stack[1], result);
           //check
           for(int i = 2;i <= nm[0]; i++)
            {
                if (res[i] == 0)
                {
                    RESULT("No");
                    return;
                }
            }
            RESULT("Yes");
            for (int i = 2; i <= nm[0]; i++)
            {
                RESULT(res[i]);
            }


        }

        class TreeNode<T>
        {
            public static bool StopOp = false;
            public static void DFS(TreeNode<T> root, Func<T,T> on_visited,bool loop=false,int mark=0)
            {
                if (root == null) return;
                if (!loop)
                {
                    Random r = new Random();
                     mark = r.Next(int.MinValue, int.MaxValue);
                    loop = true;
                }
                on_visited(root.Item);
                root.visited_mark = mark;
                if (root.Children.Count > 0)
                {
                    foreach (var node in root.Children)
                    {
                        if (node.visited_mark!=mark)
                        {
                            DFS(node,on_visited,loop,mark);
                        }
                    }
                }
            }
            public static void BFS(TreeNode<T> root, Func<T,int,T, T> on_visited)
            {
                if (root == null) return;
                int acc = 1;
                var queue = new Queue<TreeNode<T>>();
                on_visited(root.Item,0,root.Item);
                Random r = new Random();
                int mark = r.Next(int.MinValue,int.MaxValue);
                root.visited_mark = mark;
                queue.Enqueue(root);
                int dept = 1;
                while (queue.Count != 0)
                {
                 //   RESULT("loop");
                    TreeNode<T> current = queue.Dequeue();
                    if (current.Children.Count > 0)
                    {
                        foreach (var node in current.Children)
                        {
                       
                            if (node.visited_mark != mark)
                            {
                                on_visited(node.Item,dept,current.Item);
                                node.visited_mark = mark;
                                acc++;
                                if (TreeNode<T>.StopOp) {
                                        break; }
                                queue.Enqueue(node);
                            }
                        }
                    }
             if(acc>0)   dept++;
                 //   RESULT("acc:" + queue.Count);
                 acc = 0;
                    if (TreeNode<T>.StopOp) { break; }
                }
                TreeNode<T>.StopOp = false;
            }
            List<TreeNode<T>> Children;

            T Item { get; set; }
            int visited_mark { get; set; }
            public TreeNode(T item)
            {
                Item = item;
                Children = new List<TreeNode<T>>();
            }

            public TreeNode<T> AddChild(T item)
            {
                TreeNode<T> nodeItem = new TreeNode<T>(item);
                Children.Add(nodeItem);
                return nodeItem;
            }
            public void AddChildRelative(TreeNode<T> item)
            {
                Children.Add(item);
            }
        }

        static void addarray(long[] arr, int start, int end)
        {
            for (int i = start; i <= end; i++)
            {
                arr[i]++;
            }
        }
        public static decimal Sqrt(decimal x)
        {
            decimal sqrt_x = (decimal)Math.Sqrt((long)x);
            for (int i = 0; i < 10; ++i)
                sqrt_x = 0.5m * (sqrt_x + x / sqrt_x);
            return sqrt_x;
        }
        static long summ(long s)
        {
            if (s == 1) return 1;
            return s + summ(s - 1);
        }
        public static bool checka(int[] a, int m)
        {
            int back = 1;
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] >= 1 && a[i] <= m)
                {
                    if (a[i] >= back)
                    {
                        back = a[i];
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
        public static ulong pow(int a, int b)
        {
            ulong res = 1;
            for (int i = 0; i < b; i++)
            {
                res *= (ulong)a;
            }
            return res;
        }
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static long s2l(String s)
        {
            return Convert.ToInt64(s);
        }
        static void RESULT(double res, bool debug = false)
        {
            if (debug)
            {
#if DEBUG
                Console.Write("[DEBUG]");
                Console.WriteLine(res);
#endif
            }
            else
            {
                Console.WriteLine(res);
            }
        }
        static void RESULT(long res, bool debug = false)
        {
            if (debug)
            {
#if DEBUG
                Console.Write("[DEBUG]");
                Console.WriteLine(res);
#endif
            }
            else
            {
                Console.WriteLine(res);
            }
        }
        static void RESULT(ulong res, bool debug = false)
        {
            if (debug)
            {
#if DEBUG
                Console.Write("[DEBUG]");
                Console.WriteLine(res);
#endif
            }
            else
            {
                Console.WriteLine(res);
            }
        }
        static void RESULT(int res, bool debug = false)
        {
            if (debug)
            {
#if DEBUG
                Console.Write("[DEBUG]");
                Console.WriteLine(res);
#endif
            }
            else
            {
                Console.WriteLine(res);
            }
        }
        static void RESULT(String res,bool debug=false)
        {
            if (debug)
            {
#if DEBUG
                Console.Write("[DEBUG]");
                Console.WriteLine(res);
#endif
            }
            else
            {
                Console.WriteLine(res);
            }
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] s2iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] s2larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
        static ulong[] s2larray2(String[] src)
        {
            int len = src.Length;
            ulong[] res = new ulong[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToUInt64(src[i]);
            }
            return res;
        }

        static long C(int n, int r)
        {
            if (n <= 1) return 0;
            if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
            long ans = 1;
            int i;

            for (i = 1; i <= r; i++)
            {
                ans *= n - r + i;
                ans /= i;
            }

            return ans;
        }
        static long C(long n, long r)
        {
            if (n <= 1) return 0;
            if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
            long ans = 1;
            int i;

            for (i = 1; i <= r; i++)
            {
                ans *= n - r + i;
                ans /= i;
            }

            return ans;
        }
        static ulong C(ulong n, ulong r)
        {
            if (n <= 1) return 0;
            if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
            ulong ans = 1;
            ulong i;

            for (i = 1; i <= r; i++)
            {
                ans *= n - r + i;
                ans /= i;
            }

            return ans;
        }


    }

}