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: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;

namespace x
{
    class Program
    {
        static void Main(string[] args)
        {
            (var vCount, var edgeCount) = IOUtils.Read2Ints();

            var edges = IOUtils.ReadIntLines(edgeCount);

            var graph = new Dijkstra(vCount, false);
            foreach (var edge in edges)
            {
                graph.AddEdge(edge[0], edge[1], 1);
            }
            graph.Calc(1, null);

            System.Console.WriteLine("Yes");
            for (int i = 2; i <= vCount; i++)
            {
                System.Console.WriteLine(graph.GetPreVertex(i).Value);
            }
        }
    }


    /// <summary>
    /// ダイクストラ法で最短経路を計算
    /// </summary>
    class Dijkstra
    {
        readonly int vertexCount;
        readonly bool hasDirection;
        readonly IReadOnlyDictionary<int, Node> nodeDic;

        public struct Edge
        {
            public readonly int dest;
            public readonly int weight;

            public Edge(int dest, int weight)
            {
                this.dest = dest;
                this.weight = weight;
            }
        }

        class Node
        {
            public int V { get; }
            private readonly Dictionary<int, Edge> nextDic = new Dictionary<int, Edge>();

            public Node(int v)
            {
                this.V = v;
            }

            public bool HasNext(int v)
            {
                return this.nextDic.ContainsKey(v);
            }
            public void AddNext(int v, int weight)
            {
                if (v == this.V) throw new ArgumentException("ループには対応していません");
                this.nextDic[v] = new Edge(v, weight);
            }
            public IReadOnlyCollection<Edge> AllNexts()
            {
                return this.nextDic.Values;
            }
            public bool RemoveNext(int v)
            {
                return this.nextDic.Remove(v);
            }
            public int? TryGetWeight(int v)
            {
                Edge res;
                return this.nextDic.TryGetValue(v, out res) ? res.weight : (int?)null;
            }

            public int? CurrentWeight { get; private set; }
            public int? CurrentPreVertex { get; private set; }
            public bool IsCommitted { get; private set; }
            public void Commit()
            {
                this.IsCommitted = true;
            }

            public bool TryUpdateWeight(int weight, int? pre)
            {
                if (this.IsCommitted) return false;
                if (CurrentWeight == null || weight < CurrentWeight.Value)
                {
                    this.CurrentPreVertex = pre;
                    this.CurrentWeight = weight;
                    return true;
                }
                return false;
            }

        }

        public Dijkstra(int vertexCount, bool hasDirection)
        {
            this.vertexCount = vertexCount;
            this.hasDirection = hasDirection;

            this.nodeDic = Enumerable.Range(1, vertexCount)
                                .ToDictionary(v => v, v => new Node(v));
        }
        public void AddEdge(int v1, int v2, int weight)
        {
            if (weight < 0) throw new ArgumentOutOfRangeException(nameof(weight));
            this.nodeDic[v1].AddNext(v2, weight);
            if (!this.hasDirection)
            {
                this.nodeDic[v2].AddNext(v1, weight);
            }
        }
        public bool RemoveEdge(int v1, int v2)
        {
            if (!this.nodeDic[v1].RemoveNext(v2)) return false;
            if (!this.hasDirection)
            {
                if (!this.nodeDic[v2].RemoveNext(v1))
                {
                    throw new InvalidProgramException("invalid state " + v1 + "," + v2);
                }
            }
            return true;
        }

        public void Calc(int start, int? goal)
        {
            var queue = new PriorityQueue<Node>(vertexCount, n => (n.CurrentWeight ?? 0) * -1);
            this.nodeDic[start].TryUpdateWeight(0, null);
            queue.Enqueue(this.nodeDic[start]);

            while (queue.Count > 0)
            {
                var pre = queue.Dequeue();
                if (pre == null) break;
                pre.Commit();
                if (goal != null && pre.V == goal) break;

                foreach (var next in pre.AllNexts())
                {
                    var newWeight = pre.CurrentWeight + next.weight;
                    if (this.nodeDic[next.dest].TryUpdateWeight(pre.V, newWeight))
                    {
                        queue.Enqueue(this.nodeDic[next.dest]);
                    }
                }
            }
        }

        public int? GetPreVertex(int v)
        {
            return this.nodeDic[v].CurrentPreVertex;
        }
    }

    class PriorityQueue<T>
    {
        readonly T[] array;
        readonly Func<T, int> valueSelector;
        public int Count { get; private set; }


        public PriorityQueue(int capacity, Func<T, int> valueSelector)
        {
            this.array = new T[capacity];
            this.valueSelector = valueSelector;
        }

        public void Enqueue(T item)
        {
            this.array[this.Count] = item;
            this.Count += 1;
            this.UpHeap();
        }

        public T Dequeue()
        {
            // 先頭要素を末尾にして再構成
            this.Swap(0, this.Count - 1);
            this.Count -= 1;
            this.DownHeap();

            return this.array[this.Count];
        }


        private void UpHeap()
        {
            var n = this.Count - 1;
            while (n != 0)
            {
                // 親要素の座標
                var parent = (n - 1) / 2;

                if (this.valueSelector(this.array[n]) > this.valueSelector(this.array[parent]))
                {
                    this.Swap(n, parent);
                    n = parent;
                }
                else
                {
                    break;
                }
            }
        }

        private void DownHeap()
        {
            var parent = 0;
            while (true)
            {
                var child = 2 * parent + 1;
                if (child > this.Count - 1) break;

                if (child < this.Count - 1 && this.valueSelector(this.array[child]) < this.valueSelector(this.array[child + 1]))
                {
                    // 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
                    child += 1;
                }

                if (this.valueSelector(this.array[parent]) < this.valueSelector(this.array[child]))
                {
                    this.Swap(parent, child);
                    parent = child;
                }
                else
                {
                    break;
                }
            }
        }

        private void Swap(int a, int b)
        {
            var tmp = this.array[a];
            this.array[a] = this.array[b];
            this.array[b] = tmp;
        }
    }
    
    static class IOUtils
    {
        public static (int a, int b) Read2Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1]);
        }
        public static (int a, int b, int c) Read3Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1], vals[2]);
        }
        public static IEnumerable<int[]> ReadIntLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadInts();
            }
        }
        public static IEnumerable<long[]> ReadLongLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadLongs();
            }
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        public static ulong ReadUlong()
        {
            return ulong.Parse(Console.ReadLine());
        }
        public static int[] ReadInts()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        }
        public static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}