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

namespace ABC168
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_D();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var n = Ex.Read;

            int i = n.LastOrDefault() - '0';
            if (i == 2 || i == 4 || i == 5 || i == 7 || i == 9) "hon".Cw();
            else if (i == 3) "bon".Cw();
            else "pon".Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var k = Ex.ReadInt;
            var s = Ex.Read;

            if (s.Length <= k) s.Cw();
            else
            {
                (string.Join("", s.Take(k)) + "...").Cw();
            }
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
            var l = Ex.ReadIntArray();
            var a = l[0];
            var b = l[1];
            var h = l[2];
            var m = l[3];

            double sh = 30 * h + m * .5;
            double lo = m * 6;
            var d = Math.Abs(sh - lo);
            d = Math.Min(360 - d, d);
            var c = a * a + b * b - 2 * a * b * Math.Cos(d * Math.PI / 180.0);
            Math.Sqrt(c).Cw();
        }
    }
    public class ABC_D
    {
        List<long>[] arr;
        long[] to;
        long[] min;
        long n;
        long m;
        bool b = true;

        public ABC_D()
        {
            var l = Ex.ReadLongArray();
            // N個の部屋とM本の通路
            // 部屋1は洞窟の入り口がある特別
            // 部屋1以外の各部屋に1つずつ道しるべ
            // 道しるべを見て、それが指す部屋に移動する」ことを繰り返すと、部屋1に最小の移動回数でたどり着く。
            n = l[0];
            m = l[1];

            arr = new List<long>[n + 1];
            to = new long[n + 1];
            min = new long[n + 1];

            for (int i = 0; i <= n; i++)
            {
                min[i] = long.MaxValue;
                arr[i] = new List<long>();
            }

            for (int i = 0; i < m; i++)
            {
                var a = Ex.ReadLongArray();
                arr[a[0]].Add(a[1]);
                arr[a[1]].Add(a[0]);
            }

            Queue<long> q = new Queue<long>();
            q.Enqueue(1);
            long cou = 0;
            while (q.Any())
            {
                cou++;
                var i = q.Dequeue();
                foreach (var v in arr[i])
                {
                    if (cou < min[v])
                    {
                        min[v] = cou;
                        to[v] = i;
                        q.Enqueue(v);
                    }
                }
            }

            b.YesNo();
            if (b)
            {
                for (int i = 2; i <= n; i++)
                {
                    to[i].Cw();
                }
            }
        }
    }
    public class ABC_E
    {
        long[][] arr;
        long[] w;
        long n;

        public ABC_E()
        {
            n = Ex.ReadLong;

            arr = new long[n][];
            w = new long[n];

            for (int i = 0; i < n; i++)
            {
                arr[i] = Ex.ReadLongArray();
                w[i] = arr[i][0] * arr[i][0];
            }

            w = w.OrderBy(v => v).ToArray();

            for (long i = 0; i < w.Length; i++)
            {

            }

            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    bool b = 0 == arr[i][0] * arr[j][0] + arr[i][1] + arr[j][1];
                }
            }
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 41008