using System.Collections;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Numerics;



class Program
{
    #region Reader
    //static Vector2Int ReadVec2Int
    //{
    //    get
    //    {
    //        string[] s = Console.ReadLine().Split(' ');
    //        return new Vector2Int(int.Parse(s[0]), int.Parse(s[1]));
    //    }
    //}
    //static Vector2Int[] ReadVec2Ints(int n)
    //{
    //    List<Vector2Int> list = new List<Vector2Int>();
    //    for (int i = 0; i < n; ++i)
    //    {
    //        var ab = ReadInts;
    //        list.Add(new Vector2Int(ab[0], ab[1]));
    //    }
    //    return list.ToArray();
    //}
    //static HashSet<Vector2Int> ReadVec2IntHash(int n)
    //{
    //    HashSet<Vector2Int> hash = new HashSet<Vector2Int>();
    //    for (int i = 0; i < n; ++i)
    //    {
    //        var ab = ReadInts;
    //        hash.Add(new Vector2Int(ab[0], ab[1]));
    //    }
    //    return hash;
    //}
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static long[,] ReLongMatrix(int r, int c)
    {
        var mat = new long[r, c];
        for (int i = 0; i < r; ++i)
        {
            var x = ReadLongs;
            for (int j = 0; j < c; ++j)
            {
                mat[i, j] = x[j];
            }
        }
        return mat;
    }
    static Tuple<string, string>[] ReTupleStr(int n)
    {
        List<Tuple<string, string>> list = new List<Tuple<string, string>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadStrs;
            list.Add(new Tuple<string, string>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<long, long>[] ReTupleLong(int n)
    {
        List<Tuple<long, long>> list = new List<Tuple<long, long>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadLongs;
            list.Add(new Tuple<long, long>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<int, int>[] ReadTupleInt(int n)
    {
        List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            list.Add(new Tuple<int, int>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<double, double>[] ReTupleDouble(int n)
    {
        List<Tuple<double, double>> list = new List<Tuple<double, double>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadLongs;
            list.Add(new Tuple<double, double>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M)
    {
        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 = ReadInts;
            dict[ab[0]].Add(ab[1]);
            dict[ab[1]].Add(ab[0]);
        }
        return dict;
    }
    #endregion
    static void Swap<T>(ref T a, ref T b)
    {
        T temp = a;
        a = b;
        b = temp;
    }
    static int mod = (int)Pow(10, 9) + 7;

    static void Main()
    {
        int[] NM = ReadInts;
        int N = NM[0];
        int M = NM[1];


        int[][] ABs = new int[M][];
        List<int>[] roads = new List<int>[N];

        for (int i = 0; i < roads.Length; i++)
        {
            roads[i] = new List<int>();
        }

        for (int i = 0; i < M; i++)
        {
            ABs[i] = ReadInts;
            ABs[i][0]--;
            ABs[i][1]--;
            roads[ABs[i][0]].Add(ABs[i][1]);
            roads[ABs[i][1]].Add(ABs[i][0]);
        }

        int[][] ans = new int[N][];
        ans[0] = new int[2] { -1, 0 };

        for (int i = 0; i < N; i++)
        {
            ans[i] = new int[2] {-1,100000000 };
        }

        Queue<int[]> queue = new Queue<int[]>();
        queue.Enqueue(new int[2] {0,0 });
        bool[] done = new bool[N];

        int[] a = new int[N - 1];

        while (queue.Count > 0)
        {
            int[] current = queue.Dequeue();

            foreach (var dir in roads[current[0]])
            {
                if (!done[dir])
                {
                    if (dir != 0)
                    {
                        a[dir - 1] = current[0] + 1;
                    }

                    int time = current[1] + 1;
                    int[] next = new int[2] { dir , time };
                    queue.Enqueue(next);
                    done[dir] = true;

                }

            }
        }

        WriteLine("Yes");
        WriteLine(string.Join("\n",a));
    }

}


Measured memory_bytes: 60224