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# (Mono-csc 3.5.0) (judge verdict: Accepted)

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

namespace Contest
{
  class Program
  {
    static void Main(string[] args)
    {
      ABC168.D();
    }
    class ABC168
    {
      public static void A()
      {
        var N = Read.Int();
        switch (N % 10)
        {
          case 0:
          case 1:
          case 6:
          case 8:
            Console.WriteLine("pon");return;
          case 3:
            Console.WriteLine("bon");return;
          case 2:
          case 4:
          case 5:
          case 7:
          case 9:
            Console.WriteLine("hon");return;
        }
      }
      public static void B()
      {
        var K = Read.Int();
        var S = Read.Str();
        Console.WriteLine(S.Length <= K ? S : S.Substring(0, K) + "...");
      }
      public static void C()
      {
        var A = Read.Int();
        var B = Read.Int();
        var H = Read.Int();
        var M = Read.Int();
        var r1 = Math.PI * (H * 60 + M) / 360;
        var r2 = Math.PI * M / 30;
        var x1 = Math.Cos(r1) * A;
        var y1 = Math.Sin(r1) * A;
        var x2 = Math.Cos(r2) * B;
        var y2 = Math.Sin(r2) * B;
        Console.WriteLine(Math.Sqrt(Math.Max(0, (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))));
      }
      public static void D()
      {
        var N = Read.Int();
        var M = Read.Int();
        var Adj = Read.AdjacencyList(N, M);
        var ans = Enumerable.Range(0, N + 1).Select(i => -1).ToArray();
        var queue = new Queue<int>();
        queue.Enqueue(1);
        while (queue.Count > 0)
        {
          var v = queue.Dequeue();
          foreach(var w in Adj[v])
          {
            if (ans[w] >= 0) { continue; }
            ans[w] = v;
            queue.Enqueue(w);
          }
        }
        if (ans.Skip(2).Count(x => x < 0) > 0) { Console.WriteLine("No"); return; }
        Console.WriteLine("Yes");
        Console.WriteLine(String.Join(Environment.NewLine, ans.Skip(2)));
      }
      public static void E()
      {
        var N = Read.Int();
        var AB = Read.TupleLong(N);
        var Zero = new List<Tuple<long, long>>();
        var D1 = new List<Tuple<long, long>>();
        var D2 = new List<Tuple<long, long>>();

        var count1 = new Dictionary<long, Dictionary<long, long>>();
        var count2 = new Dictionary<long, Dictionary<long, long>>();

        foreach (var t in AB)
        {
          var X = t.Item1;
          var Y = t.Item2;
          if (X == 0 && Y == 0) { Zero.Add(new Tuple<long, long>(0, 0)); continue; }
          if (Y < 0)
          {
            X *= -1;
            Y *= -1;
          }
          var gcd = Util.GCD(Math.Abs(X), Y);
          X /= gcd;
          Y /= gcd;
          if (X >= 0)
          {
            if (!count1.ContainsKey(X)) { count1.Add(X, new Dictionary<long, long>()); }
            if (!count1[X].ContainsKey(Y)) { count1[X].Add(Y, 0); }
            count1[X][Y]++;
          }
          else
          {
            if (!count2.ContainsKey(X)) { count2.Add(X, new Dictionary<long, long>()); }
            if (!count2[X].ContainsKey(Y)) { count2[X].Add(Y, 0); }
            count2[X][Y]++;
          }
        }

        MOD two = 2;
        MOD ans = 1;
        foreach(var kvp1 in count1)
        {
          foreach(var kvp2 in kvp1.Value)
          {
            var X = kvp1.Key;
            var Y = kvp2.Key;
            var C = kvp2.Value;
            if (count2.ContainsKey(-Y) && count2[-Y].ContainsKey(X))
            {
              var C2 = count2[-Y][X];
              count2[-Y][X] = 0;
              ans = ans * (two.Power(C) + two.Power(C2) - 1);
            }
            else
            {
              ans = ans * (two.Power(C) - 0);
            }
          }
        }
        foreach (var kvp1 in count2)
        {
          foreach (var kvp2 in kvp1.Value)
          {
            ans = ans * two.Power(kvp2.Value);
          }
        }
        Console.WriteLine((ans + Zero.Count - 1).V);
      }
      public static void F()
      {

      }
    }


    class Util
    {
      public static long[] ASum(long[] array)
      {
        var res = new long[array.Length + 1];
        for (int i = 0; i < array.Length; ++i)
        {
          res[i + 1] = res[i] + array[i];
        }
        return res;
      }
      public static Dictionary<T, long> Frequency<T>(T[] array)
      {
        var dict = new Dictionary<T, long>();
        foreach (var a in array)
        {
          if (!dict.ContainsKey(a)) { dict.Add(a, 0); }
          dict[a]++;
        }
        return dict;
      }
      public static long GCD(long a, long b)
      {
        while (b > 0)
        {
          var c = a % b;
          a = b;
          b = c;
        }
        return a;
      }
    }
    struct MOD
    {
      public static long P = 1000000007;
      public readonly long V;

      public MOD(long a) { this.V = a % P; }
      public static implicit operator MOD(long a) { return new MOD(a); }
      public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); }
      public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); }
      public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); }
      public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); }
      public MOD Inverse()
      {
        long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0;
        while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; }
        c %= p;
        return c + (c < 0 ? p : 0);
      }
      public MOD Power(long n)
      {
        long a = V, p = P; long res = 1; long mult = a;
        for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; }
        return res;
      }
      public override string ToString() { return V.ToString(); }
    }


    static class Read
{
static Queue<string> queue = new Queue<string>();
static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
public static ulong[] ULongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToUInt64(s)).ToArray(); }
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; }
public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false)
{
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); }
        for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } }
        return dict;
}
public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
{
Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); }
for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); }
return dict;
}
}
    }
}