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++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#define mod 1000000007
#define REP(i, n) for (unsigned long long i = 0; i < (n); i++)
#define FOR(i, a, b) for (unsigned long long i = (a); i <= (b); i++)
#define FORD(i, a, b) for (unsigned long long i = (a); i >= (b); i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define debug(x) cout << #x << '=' << (x) << endl;
#define debugp(x) cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define debug2(x, y) cout << "{" << #x << ", " << #y << "} = {" << (x) << ", " << (y) << "}" << endl;
#define debugv(v)         \
    cout << #v << " : ";  \
    for (auto x : v)      \
        cout << x << ' '; \
    cout << endl;
#define all(x) x.begin(), x.end()
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
typedef long long ll;
typedef unsigned long long ull;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n)
{
    int res = 0;
    while (n && ++res)
        n -= n & (-n);
    return res;
}
template <class T>
void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
void chmin(T &a, const T &b) { a = min(a, b); }

long long int gcd(long long int a, long long int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

long long int lcm(long long int a, long long int b)
{
    return (a * b) / gcd(a, b);
}

long long int max(long long int a, long long int b)
{
    if (a > b)
        return a;
    return b;
}

long long int power(long long int x, long long int y)
{
    long long int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

long long int powermod(long long int x, long long int y)
{
    long long int res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

long long mulmod(long long a, long long b)
{
    long long res = 0;
    a %= mod;
    while (b)
    {
        if (b & 1)
            res = (res + a) % mod;
        a = (2 * a) % mod;
        b >>= 1;
    }

    return res;
}

bool isPrime(long long int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

long double dist(long long int x1, long long int y1, long long int x2, long long int y2)
{
    return (long double)sqrt((long double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}
long long int squaredist(long long int x1, long long int y1, long long int x2, long long int y2)
{
    return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

long long int nCr(long long int n, long long int r)
{
    if (r == 0)
        return 1;
    return (n * nCr(n - 1, r - 1)) / r;
}

long long int countDivisors(long long int n)
{
    long long int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;
            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

unsigned long long int countDivisibles(unsigned long long int A, unsigned long long int B, unsigned long long int M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    return (B / M) - (A / M);
}

long long int xorRange(long long int x, long long int y)
{
    if (x % 2 == 0)
    {
        long long int pattern[] = {y, 1, y + 1, 0};
        return pattern[(int)((y - x) % 4)];
    }
    else
    {
        long long int pattern[] = {x, x ^ y, x - 1, (x - 1) ^ y};
        return pattern[(int)((y - x) % 4)];
    }
}

unsigned long long int maxOrRange(unsigned long long int l, unsigned long long int r)
{
    while (l < r)
        l &= (l + 1);
    return (l & r);
}

long long mul(long long a, long long b)
{
    return (a * b) % mod;
}

long long mul(long a, long long b, long long c)
{
    return mul(mul(a, b), c);
}

long long mul(long long a, long long b, long long c, long long d)
{
    return mul(mul(a, b), mul(c, d));
}

long long add(long long a, long long b)
{
    return (a + b) % mod;
}

long long neg(long long a)
{
    return (mod - (a % mod)) % mod;
}

long long sub(long long a, long long b)
{
    return add(a, neg(b));
}

long long minv(long long a)
{
    int b = mod - 2;
    long long ans = 1;
    while (b)
    {
        if (b % 2)
            ans = mul(ans, a);
        a = mul(a, a);
        b /= 2;
    }
    return ans;
}

long long divi(long long a, long long b)
{
    return mul(a, minv(b));
}

bool sortdesc(const std::tuple<int, int, int> &a, const std::tuple<int, int, int> &b)
{
    return (std::get<0>(a) > std::get<0>(b));
}

std::vector<long long> fni(100000);
std::vector<long long> nni(100000);
std::vector<long long> fact(100000);

void Inv_Num_Fact_Factorial(long long p, long long N)
{
    fni[0] = fni[1] = nni[0] = nni[1] = fact[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        if (i >= 2)
        {
            nni[i] = mul(nni[p % i], (p - p / i));
            fni[i] = mul(nni[i], fni[i - 1]);
        }
        fact[i] = mul(fact[i - 1], i);
    }
}

long long fnCr(long long int N, long long int R)
{
    return mul(fact[N], fni[R], fni[N - R]);
}

bool findParity(int x)
{
    int y = x ^ (x >> 1);
    y = y ^ (y >> 2);
    y = y ^ (y >> 4);
    y = y ^ (y >> 8);
    y = y ^ (y >> 16);
    if (y & 1) return 1;
    return 0;
}

using namespace std;

void add_edge(vector<int> adj[], int src, int dest) 
{ 
    adj[src].push_back(dest); 
    adj[dest].push_back(src); 
} 
  
// a modified version of BFS that stores predecessor 
// of each vertex in array p 
// and its distance from source in array d 
bool BFS(vector<int> adj[], int src, int dest, int v, 
         int pred[], int dist[]) 
{ 
    // a queue to maintain queue of vertices whose 
    // adjacency list is to be scanned as per normal 
    // DFS algorithm 
    list<int> queue; 
  
    // boolean array visited[] which stores the 
    // information whether ith vertex is reached 
    // at least once in the Breadth first search 
    bool visited[v]; 
  
    // initially all vertices are unvisited 
    // so v[i] for all i is false 
    // and as no path is yet constructed 
    // dist[i] for all i set to infinity 
    for (int i = 0; i < v; i++) { 
        visited[i] = false; 
        dist[i] = INT_MAX; 
        pred[i] = -1; 
    } 
  
    // now source is first to be visited and 
    // distance from source to itself should be 0 
    visited[src] = true; 
    dist[src] = 0; 
    queue.push_back(src); 
  
    // standard BFS algorithm 
    while (!queue.empty()) { 
        int u = queue.front(); 
        queue.pop_front(); 
        for (int i = 0; i < adj[u].size(); i++) { 
            if (visited[adj[u][i]] == false) { 
                visited[adj[u][i]] = true; 
                dist[adj[u][i]] = dist[u] + 1; 
                pred[adj[u][i]] = u; 
                queue.push_back(adj[u][i]); 
  
                // We stop BFS when we find 
                // destination. 
                if (adj[u][i] == dest) 
                    return true; 
            } 
        } 
    } 
  
    return false; 
} 
  
// utility function to print the shortest distance 
// between source vertex and destination vertex 
int printShortestDistance(vector<int> adj[], int s, 
                           int dest, int v) 
{ 
    // predecessor[i] array stores predecessor of 
    // i and distance array stores distance of i 
    // from s 
    int pred[v], dist[v]; 
  
    if (BFS(adj, s, dest, v, pred, dist) == false) { 
        // cout << "Given source and destination"
        //      << " are not connected"; 
        return -1; 
    } 
  
    // vector path stores the shortest path 
    vector<int> path; 
    int crawl = dest; 
    path.push_back(crawl); 
    while (pred[crawl] != -1) { 
        path.push_back(pred[crawl]); 
        crawl = pred[crawl]; 
    } 
  
    // distance from source is in distance array 
    // cout << dist[dest]; 
  
    // // printing path from source to destination 
    // cout << "\nPath is::\n"; 
    // for (int i = path.size() - 1; i >= 0; i--) 
    //     cout << path[i] << " ";
    // cout << path[path.size()-2] << "\n";
    return path[1]+1; 
} 



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int a,b;
    cin >> a >> b;
    vector<int> adj[a];
    REP(i,b){
        int x,y;
        cin >> x >> y;
        add_edge(adj,x-1,y-1);
    }
    bool check = false;
    int arr[a-1];
    FOR(i,1,a-1){
        int y = printShortestDistance(adj,0,i,a);
        // cout << y << " ";
        if(y==-1){
            check = true;
            break;
        }
        else{
            arr[i-1] = y;
        }
    }
    if(check){
        cout << "NO";
    } 
    else{
        cout << "YES\n";
        REP(i,a-1) cout << arr[i] << "\n";
    }
}