stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1e5+5,inf=0x3f3f3f3f;

#define mst(a) memset(a,0,sizeof a)

int n,d[N],vis[N],sign[N],m;

vector<int>e[N<<1];

void spfa(){

	queue<int>q;

	for(int i=1;i<=n;i++) d[i]=inf;

	q.push(1);vis[1]=1,d[1]=0;

	while(q.size()){

		int u=q.front();q.pop();vis[u]=0;

		for(auto v:e[u]){

			if(d[v]>d[u]+1){

				d[v]=d[u]+1;

				sign[v]=u;

				if(!vis[v]) q.push(v),vis[v]=1; 

			}

		}

	}

	int ok=0;

	for(int i=2;i<=n;i++) 

	if(d[i]==inf){

		 ok=1;

		 break;

	}

	if(ok) puts("No");

	else {

		puts("Yes");

		for(int i=2;i<=n;i++)

			printf("%d\n",sign[i]);

	}

} 

int main(){

	scanf("%d%d",&n,&m);

	for(int i=1,u,v;i<=m;i++){

		scanf("%d%d",&u,&v);

		e[u].push_back(v);

		e[v].push_back(u); 

	} 

	spfa();

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 1.829630743721415x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1e5+5;

#define mst(a) memset(a,0,sizeof a)

vector<int>e[N];

int n,m,ans[N];

int main(){

	scanf("%d%d",&n,&m);

	for(int i=1,u,v;i<=m;i++){

		scanf("%d%d",&u,&v);

		e[u].push_back(v),e[v].push_back(u);

	}

	ans[1]=1;

	queue<int>q;

	q.push(1);

	while(q.size()){

		int u=q.front();q.pop();

		for(auto v:e[u])

			if(!ans[v]) ans[v]=u,q.push(v); 

	}

	puts("Yes");

	for(int i=2;i<=n;i++) printf("%d\n",ans[i]);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define rep(i,n) for(int i = 0;i<n;i++)

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const int INF = 1001001001;

vector<int>to[100005];

int main() {

    int n,m;

    cin >> n >> m;

    rep(i,m) {

        int a,b;

        cin >> a >> b;

        --a;--b;

        to[a].push_back(b);

        to[b].push_back(a);

    }   

    queue<int> q;

    vector<int>dist(n,INF);

    vector<int>pre(n,-1);

    dist[0] = 0;

    q.push(0);

    while(!q.empty()) {

        int v = q.front();q.pop();

        for(int u:to[v]) {

            if(dist[u] != INF) continue;

            dist[u] += dist[v]+1;

            pre[u] = v;

            q.push(u);

        }

    }

    cout << "Yes" << endl;

    rep(i,n) {

        if(i==0) continue;

        int ans = pre[i];

        ++ans;

        cout << ans << endl;

    }

}

// Faster C++ solution for the same problem (measured speedup: 3.494052950005431x):
#include<bits/stdc++.h>

#define rep(i,n) for(int i = 0;i<n;i++)

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}



const int INF = 1001001001;

int main() {

    int n,m;

    cin >> n >> m;

    vector<vector<int>>g(n);

    rep(i,m) {

        int a,b;

        cin >> a >> b;

        a--;b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    vector<int>prev(n,-1);

    vector<int>dist(n,INF);

    dist[0] = 0;

    queue<int>q;

    q.push(0);

    while(!q.empty()) {

        int v = q.front();q.pop();

        for(auto nv : g[v]) {

            if(dist[nv] == INF) {

                dist[nv] = dist[v] + 1;

                q.push(nv);

                prev[nv] = v;

            }

        }

    }

    for(int i = 1;i<n;i++) {

        if(prev[i] == -1) {

            cout << "No" << endl;

            return 0;

        }

    }

    cout << "Yes" << endl;

    for(int i = 1;i<n;i++) {

        cout << prev[i] + 1 << endl;

    }

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



vector<int> edge[100001];



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n, m;

  cin >> n >> m;

  while (m--) {

    int a, b;

    cin >> a >> b;

    a--;

    b--;

    edge[a].emplace_back(b);

    edge[b].emplace_back(a);

  }

  queue<int> q;

  vector<int> bfs(n, -1);

  vector<int> prv(n);

  bfs[0] = 0;

  prv[0] = -1;

  q.push(0);

  while (!q.empty()) {

    int i = q.front();

    q.pop();

    for (auto ed : edge[i]) {

      if (bfs[ed] == -1) {

        bfs[ed] = bfs[i] + 1;

        prv[ed] = i;

        q.push(ed);

      }

    }

  }

  cout << "Yes" << '\n';

  for (int i = 1; i < n; i++) {

    cout << prv[i] + 1 << '\n';

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.479599776362176x):
#include <bits/stdc++.h>



#define rep(i, n) for (int i = 0; i < (n); i++)



using namespace std;



using ll = long long;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n, m;

  cin >> n >> m;

  vector<int> to[n];

  rep(i, m) {

    int a, b;

    cin >> a >> b;

    a--, b--;

    to[a].emplace_back(b);

    to[b].emplace_back(a);

  }

  vector<int> ans(n, -1);

  ans[0] = 1;

  queue<int> q;

  q.push(0);

  while (!q.empty()) {

    int p = q.front();

    q.pop();

    for (auto&& e : to[p]) {

      if (ans[e] != -1) continue;

      ans[e] = p;

      q.push(e);

    }

  }

  cout << "Yes" << '\n';

  for (int i = 1; i < n; i++) {

    ans[i]++;

    cout << ans[i] << '\n';

  }

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

//#define MOD 1000000007

#define MOD 998244353

#define INF 1145141919810893364

//#define INF 810114514

#define PI 3.141592653589

typedef long long ll;

typedef pair<ll,ll> PP;

#define int ll

#define setdouble setprecision

#define REP(i,n) for(int i=0;i<(n);++i)

#define OREP(i,n) for(int i=1;i<=(n);++i)

#define RREP(i,n) for(int i=(n)-1;i>=0;--i)

#define GOODBYE do { cout << "0" << endl; return 0; } while (false)

#define MM <<" "<<

#define Endl endl

#define debug false

#define debug2 false









signed main(void){

    int N,M,a;

    vector<int> A,B;

    cin >> N >> M;

    REP(i,M){

        cin >> a;a--;

        A.push_back(a);

        cin >> a;a--;

        B.push_back(a);

    }

    

    vector<int> G[214514];

    REP(i,M){

        G[A[i]].push_back(B[i]);

        G[B[i]].push_back(A[i]);

    }

    

    vector<int> Ans(N,-1);

    queue<int> Q;

    Ans[0]=0;

    Q.push(0);

    

    while(!Q.empty()){

        int q = Q.front();

        Q.pop();

        REP(i,G[q].size()){

            if(Ans[G[q][i]]==-1){

                Q.push(G[q][i]);

                Ans[G[q][i]]=q;

            }

        }

    }

    

    REP(i,N){

        if(i==0)continue;

        if(Ans[i]==-1){

            cout << "No" << endl;

            return 0;

        }

    }

    cout << "Yes" << endl;

    REP(i,N){

        if(i==0)continue;

        cout << Ans[i]+1 << endl;

    }

    

    return 0;

}






// Faster C++ solution for the same problem (measured speedup: 6.879410699183747x):
#include <bits/stdc++.h>

//using namespace std;

//#define INF 1145141919810893364

//#define REP(i,n) for(int i=0;i<(n);++i)



signed main(void){

    int N,M;

    int a,b;

    std::vector<std::vector<int>> edge;

    

    

    std::cin >> N >> M;

    edge.resize(N);

    for(int i=0;i<M;i++){

        std::cin >> a >> b;

        a--;b--;

        edge[a].push_back(b);

        edge[b].push_back(a);

    }

    

    std::vector<int> Ans(N,-1);

    std::vector<bool> visited(N,false);

    

    std::queue<int> Queue;

    Queue.push(0);

    visited[0]=true;

    

    while(!Queue.empty()){

        int t = Queue.front();

        Queue.pop();

        for(int v:edge[t]){

            if(visited[v])continue;

            Queue.push(v);

            Ans[v]=t;

            visited[v]=true;

        }

    }

    

    for(int i=1;i<N;i++){

        if(Ans[i]==-1){

            std::cout << "No" << std::endl;

            return 0;

        }

    }

    

    std::cout << "Yes" << std::endl;

    for(int i=1;i<N;i++){

        std::cout << Ans[i]+1 << std::endl;

    }

    

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

#define array(N,t) (t*)calloc(N,sizeof(t))

const int sz=2e5;

int qLen,qHead,Q[sz];

void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}

struct touple{int a;int b;};

int main(void)

{

  int A,B,N,M,x;

  x=scanf("%d %d",&N,&M);

  /*struct touple *cave=(struct touple*)malloc((2*M)*sizeof(struct touple));

  rep(i,M)

  {

    x=scanf("%d %d",&A,&B);A--,B--;

    cave[i].a=A;cave[i].b=B;

    cave[i+M].a=B;cave[i+M].b=A;

  }*/

  vector<int> room(N,-1);vector<vector<int>> cave(N);

  rep(i,M)x=scanf("%d %d",&A,&B),A--,B--,cave[A].push_back(B),cave[B].push_back(A);

  //int *room=(int*)malloc((N)*sizeof(int));

  //memset(room,0xFF,sizeof(int)*(N));

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();

    for(int y:cave[x]){if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}

// Faster C++ solution for the same problem (measured speedup: 5.104461087338428x):
#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

const int sz=1e5;

int qLen,qHead,Q[sz],*cave[sz];

void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}

int main(void)

{

  int A,B,N,M,x,y;

  x=scanf("%d %d",&N,&M);

  int room[N],path[N]={0};

  rep(i,N)room[i]=-1;

  rep(i,M)

  {

    x=scanf("%d %d",&A,&B);A--,B--;

    cave[A]=(int*)realloc(cave[A],sizeof(int)*(path[A]+2));

    cave[A][path[A]]=B;path[A]++;

    cave[B]=(int*)realloc(cave[B],sizeof(int)*(path[B]+2));

    cave[B][path[B]]=A;path[B]++;

  }

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();

    rep(i,path[x]){y=cave[x][i];if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

#define array(N,t) (t*)calloc(N,sizeof(t))

const int sz=2e5;

int qLen,qHead,Q[sz];

void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}

struct touple{int a;int b;};

int main(void)

{

  int A,B,N,M,x;

  x=scanf("%d %d",&N,&M);

  /*struct touple *cave=(struct touple*)malloc((2*M)*sizeof(struct touple));

  rep(i,M)

  {

    x=scanf("%d %d",&A,&B);A--,B--;

    cave[i].a=A;cave[i].b=B;

    cave[i+M].a=B;cave[i+M].b=A;

  }*/

  vector<int> room(N,-1);vector<vector<int>> cave(N);

  rep(i,M)x=scanf("%d %d",&A,&B),A--,B--,cave[A].push_back(B),cave[B].push_back(A);

  //int *room=(int*)malloc((N)*sizeof(int));

  //memset(room,0xFF,sizeof(int)*(N));

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();

    for(int y:cave[x]){if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}

// Faster C++ solution for the same problem (measured speedup: 5.105985140347414x):
#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

const int sz=1e5;

int qLen,qHead,Q[sz],*cave[sz];

void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}

int main(void)

{

  int A,B,N,M,x,y;

  x=scanf("%d %d",&N,&M);

  int room[N],path[N]={0};

  rep(i,N)room[i]=-1;

  rep(i,M)

  {

    x=scanf("%d %d",&A,&B);A--,B--;

    cave[A]=(int*)realloc(cave[A],sizeof(int)*(path[A]+1));

    cave[A][path[A]]=B;path[A]++;

    cave[B]=(int*)realloc(cave[B],sizeof(int)*(path[B]+1));

    cave[B][path[B]]=A;path[B]++;

  }

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();

    rep(i,path[x]){y=cave[x][i];if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

#define array(N,t) (t*)calloc(N,sizeof(t))

const int sz=2e5;

int qLen,qHead,Q[sz];

void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}

struct touple{int a;int b;};

int main(void)

{

  int A,B,N,M,x;

  x=scanf("%d %d",&N,&M);

  /*struct touple *cave=(struct touple*)malloc((2*M)*sizeof(struct touple));

  rep(i,M)

  {

    x=scanf("%d %d",&A,&B);A--,B--;

    cave[i].a=A;cave[i].b=B;

    cave[i+M].a=B;cave[i+M].b=A;

  }*/

  vector<int> room(N,-1);vector<vector<int>> cave(N);

  rep(i,M)x=scanf("%d %d",&A,&B),A--,B--,cave[A].push_back(B),cave[B].push_back(A);

  //int *room=(int*)malloc((N)*sizeof(int));

  //memset(room,0xFF,sizeof(int)*(N));

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();

    for(int y:cave[x]){if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}

// Faster C++ solution for the same problem (measured speedup: 5.099676764807402x):
#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

const int sz=1e5;

int qLen,qHead,Q[sz],*cave[sz];

void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}

int main(void)

{

  int A,B,N,M,x,y;

  x=scanf("%d %d",&N,&M);

  int room[N],path[N];

  rep(i,N)path[i]=0,room[i]=-1;

  while(~scanf("%d %d",&A,&B))

  {

    A--,B--;

    cave[A]=(int*)realloc(cave[A],sizeof(int)*(path[A]+1));cave[A][path[A]]=B;path[A]++;

    cave[B]=(int*)realloc(cave[B],sizeof(int)*(path[B]+1));cave[B][path[B]]=A;path[B]++;

  }

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();rep(i,path[x]){y=cave[x][i];if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

#define array(N,t) (t*)calloc(N,sizeof(t))

const int sz=2e5;

int qLen,qHead,Q[sz];

void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}

struct touple{int a;int b;};

int main(void)

{

  int A,B,N,M,x;

  x=scanf("%d %d",&N,&M);

  /*struct touple *cave=(struct touple*)malloc((2*M)*sizeof(struct touple));

  rep(i,M)

  {

    x=scanf("%d %d",&A,&B);A--,B--;

    cave[i].a=A;cave[i].b=B;

    cave[i+M].a=B;cave[i+M].b=A;

  }*/

  vector<int> room(N,-1);vector<vector<int>> cave(N);

  rep(i,M)x=scanf("%d %d",&A,&B),A--,B--,cave[A].push_back(B),cave[B].push_back(A);

  //int *room=(int*)malloc((N)*sizeof(int));

  //memset(room,0xFF,sizeof(int)*(N));

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();

    for(int y:cave[x]){if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}

// Faster C++ solution for the same problem (measured speedup: 5.2172005535186985x):
#include<stdio.h>

#include<stdlib.h>

#define rep(i,N) for(int i=0;i<(int)N;i++)

const int qsz=1e5;

int qLen,qHead,Q[100000],*cave[100000];

void PUSH(int n){Q[(qHead+qLen)%qsz]=n;qLen++;}

int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%qsz;return q;}

int IN(void)

{

  int x=0;short f=0,c=getchar();

  while(c<48||c>57)f^=c==45,c=getchar();

  while(c>47&&c<58)x=x*10+c-48,c=getchar();

  return f?-x:x;

}

signed main(void)

{

  int A,B,N,M,x,y;

  N=IN(),M=IN();

  int room[N],path[N];

  rep(i,N)path[i]=0,room[i]=-1;

  rep(i,M)

  {

    A=IN()-1,B=IN()-1;

    cave[A]=(int*)realloc(cave[A],sizeof(int)*(path[A]+1));cave[A][path[A]]=B;path[A]++;

    cave[B]=(int*)realloc(cave[B],sizeof(int)*(path[B]+1));cave[B][path[B]]=A;path[B]++;

  }

  room[0]=0;PUSH(0);

  while(qLen)

  {

    x=POP();rep(i,path[x]){y=cave[x][i];if(!(room[y]<0))continue;room[y]=x,PUSH(y);}

  }

  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <queue>



int main(void) {

    std::cin.tie();

    std::ios::sync_with_stdio(false);



    int n, m;

    std::cin >> n >> m;



    std::vector<std::vector<int> > graph(n);

    for (int i = 0; i < m; ++i) {

        int a, b;

        std::cin >> a >> b;

        --a, --b;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }



    std::vector<int> dist(n, -1);

    std::queue<int> que;

    std::vector<int> pre(n, -1);



    dist[0] = 0;

    que.push(0);



    while (!que.empty()) {

        int v = que.front();

        que.pop();

        for (int u : graph[v]) {

            if (dist[u] != -1)

                continue ;

            dist[u] = dist[v] + 1;

            que.push(u);

            pre[u] = v;

        }

    }



    std::cout << "Yes" << std::endl;

    for (int i = 1; i < n; ++i)

        std::cout << pre[i] + 1 << std::endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1012042829967406x):
#include <vector>

#include <queue>

#include <stdio.h>

using namespace std;



int main(void) {

    int n, m;

    scanf("%d %d", &n, &m);



    vector<vector<int> > graph(n);

    for (int i = 0 ; i < m; ++i) {

        int a, b;

        scanf("%d %d", &a, &b);

        --a, --b;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }



    vector<int> dist(n, -1);

    queue<int> que;

    vector<int> pre(n, -1);



    dist[0] = 0;

    que.push(0);



    while(!que.empty()) {

        int u = que.front();

        que.pop();

        for (int v : graph[u]) {

            if (dist[v] != -1)

                continue ;

            dist[v] = dist[u] + 1;

            que.push(v);

            pre[v] = u;

        }

    }



    printf("Yes\n");

    for (int i = 1; i < n; ++i)

        printf("%d\n", (pre[i] + 1));

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<int> to[100005];

const int inf = 100000000;



int main() {

  int N,M;

  cin >> N >> M;

  int a,b;

  for(int i=0;i<M;i++){

    cin >> a >> b;

    a--;

    b--;

    to[a].push_back(b);

    to[b].push_back(a);

  }



  queue<int> q;

  vector<int> dist(N,inf);

  vector<int> pre(N,-1);

  dist.at(0) = 0;

  q.push(0);

  while(!q.empty()){

    int v = q.front();

    q.pop();

    for(int u : to[v]){

      if(dist[u] != inf) continue;

      dist[u] = dist[v] + 1;

      pre[u] = v;

      q.push(u);

    }

  }

  

  cout << "Yes" << endl;

  

  for(int i=0;i<N;i++){

    if(i == 0) continue;

    int ans = pre[i];

    ans++;

    cout << ans << endl;

  }

  

  return(0);

}


// Faster C++ solution for the same problem (measured speedup: 3.4964599562779903x):
#include<iostream>

#include<vector>

#include<queue>

#define int long long

using namespace std;

const int inf = 1000000000;



signed main() {

  int n, m;

  cin>>n>>m;

  vector<int>g[n];

  int a, b;

  for(int i = 0; i < m; i++) {

    cin>>a>>b;

    a--;

    b--;

    g[a].push_back(b);

    g[b].push_back(a);

  }

  

  vector<int>dist(n, inf), pre(n, -1);

  queue<int>q;

  dist[0] = 0;

  q.push(0);

  while(!q.empty()){

    int v = q.front();

    q.pop();

    for(int u : g[v]){

      if(dist[u] != inf) continue;

      dist[u] = dist[v] + 1;

      pre[u] = v;

      q.push(u);

    }

  }

  

  cout<<"\nYes";

  for(int i=1; i<n; i++)

    cout<<"\n"<<pre[i]+1;

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

 

#define pb push_back

#define mp make_pair

#define f0(i,b) for(int i=0;i<(b);i++)

#define f1(i,b) for(int i=1;i<=(b);i++)

#define f2(i,a,b) for(int i=(a);i<=(b);i++)

#define sf(a) scanf("%d",&a);

#define sfl(a) scanf("%lld",&a);

 

bool vis[200005];

vector<int> v[200001];

int l[200001],p[200001];

 

void edge(int a, int b)

{

    v[a].pb(b);

    v[b].pb(a);

}

void bfs(int u)

{

    queue<int> q;

    q.push(u);

    vis[u] = true;

    int x;

    while (!q.empty()) {

 

        int f = q.front();

        q.pop();

 

        for (int i = 0; i < v[f].size(); i++){

            x = v[f][i];

            if(!vis[x]){

                q.push(x);

                l[x] = l[f] + 1;

                p[x] = f;

                vis[x] = true;

            }

        }

    }

 

}

void init(){

  for(int i = 0 ; i <= 2000; i++)

  l[i] = 0;

 

  for(int i = 0 ; i <= 2000 ; i++)

     v[i].clear();

 

}

int main(){

    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);

    //freopen("output.txt", "w", stdout);

     int node, edg, a, b;

     cin >> node >> edg;

     for(int i = 0 ; i < edg; i++){

         cin >> a >> b;

         edge(a,b);

     }

     l[1] = 1;

     bfs(1);

     int c = 0;

     for(int i = 1 ; i <= node ; i++){

       if(vis[i])

          c++;

     }

     if(c == node){

      cout << "Yes" << endl;

      for(int i = 2 ; i <= node ; i++) cout << p[i] << endl;

     }

     else cout << "No" << endl;

 

 

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8343356282379448x):
#include<bits/stdc++.h>

#define MAX 100007

using namespace std;

typedef long long ll;



ll pre[MAX],cost[MAX];

vector<ll>adj[MAX];



int main()

{

    ll t,i,n,m,a,b,co,s;

    cin >> n >> m;

    for(i=0; i<m; i++)

    {

        cin >> a >> b;

        adj[a].push_back(b);

        adj[b].push_back(a);

    }



    for(i=1; i<=n; i++)cost[i]=1e9;



    deque<ll>q;

    q.push_back(1);

    pre[1]=1;

    cost[1]=0;

    while(!q.empty())

    {

        s=q.front();

        q.pop_front();

        co=cost[s];

        for(auto s1: adj[s])

        {

            if(cost[s1]>(co+1))

            {

                cost[s1]=co+1;

                pre[s1]=s;

                q.push_back(s1);

            }

        }

    }

    ll ok=1;

    for(i=2; i<=n; i++)ok &= cost[i]!=1e9;

    if(ok==0)cout << "No\n";

    else

    {

        cout << "Yes\n";

        for(i=2; i<=n; i++)cout << pre[i] << "\n";

    }

    return 0;

}