stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <cmath>

#include <iostream>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



int main() {

	ll n,m,ch[200010];

	cin>>n>>m;

	vector<ll>a[200010];

	for(ll i=0;i<n;i++){

		ch[i]=-1;

	}

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

		ll x,y;

		cin>>x>>y;

		x--;y--;

		a[x].push_back(y);

		a[y].push_back(x);

	}

	ch[0]=0;

	queue<ll>q;

	q.push(0);

	while(q.size()!=0){

		ll now=q.front();

		q.pop();

		for(ll i=0;i<a[now].size();i++){

			ll next=a[now][i];

			if(ch[next]!=-1){

				continue;

			}

			ch[next]=now+1;

			q.push(next);

		}

	}

	cout << "Yes"<<endl;

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

		cout <<ch[i]<<endl;

	}

	// your code goes here

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#include <cmath>

#include <iostream>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



int main() {

	ll n,m;

	cin>>n>>m;

	vector<ll>ch[100010];

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

		ll x,y;

		cin>>x>>y;

		x--;y--;

		ch[x].push_back(y);

		ch[y].push_back(x);

	}

	ll ans[100010];

	for(ll i=0;i<n;i++){

		ans[i]=-1;

	}

	queue<ll>q;

	ans[0]=0;

	q.push(0);

	while(q.size()!=0){

		ll now=q.front();

		q.pop();

		//cout <<now<<endl;

		for(ll i=0;i<ch[now].size();i++){

			ll next=ch[now][i];

		//	cout <<next<<endl;

			if(ans[next]!=-1){

				continue;

			}

			ans[next]=now;

			q.push(next);

		}

	}

	cout <<"Yes"<<endl;

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

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

	}

	// your code goes here

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

} 

// Optimized solution to the same problem (faster):
#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;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

    }

}

// Optimized solution to the same problem (faster):
#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;

    }

}

    






// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}






// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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));

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

vector<int> adj[100001];

bool visited[100001];

int ans[100001];

 

void bfs(){

    queue<int> q;

    q.push(1);

    visited[1] = true;

    

    while(q.size()){

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

        for(auto i : adj[cur]){

            if(!visited[i]){

                ans[i] = cur;

                q.push(i);

                visited[i] = true;

            }

        }

    }

}

int main()

{

	memset(visited,false,sizeof(visited));

	memset(ans,0,sizeof(ans));

	int nodes,edges;

	cin >> nodes >> edges;

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

	{

		int u,v;

		cin >> u >> v;

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	bfs();

	cout << "Yes\n";

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

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

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define endl "\n" 

using namespace std;

#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;

typedef long long ll;

typedef unsigned long long ull;

bool visited[100003];

vector<int>adj[100003];

int parent[100003];

void bfs(){

    visited[1]=true;

    queue<int>qa;

    qa.push(1);

    while(qa.size()){

        int a=qa.front();

        qa.pop();

        for(auto i:adj[a]){

            if(!visited[i]){

                parent[i]=a;

                visited[i]=1;

                qa.push(i);

            }

        }

    }

}

int main()

{

    cin.sync_with_stdio(0); cin.tie(0); 

    int n,m;

    cin>>n>>m;

    while(m--){

        int a,b;

        cin>>a>>b;

        adj[a].push_back(b);

        adj[b].push_back(a);

    }

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

    parent[i]=0,visited[i]=0;

    bfs();

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

    if(!visited[i]){

        cout<<"No"<<endl;

        return 0;

    }

    cout<<"Yes"<<endl;

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

    cout<<parent[i]<<endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll inf = 1e9;

#define sz              300005

#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



int par[sz];

bool vis[sz];

vector < int > V[sz];



void bfs(int src){



    memset(vis,0,sizeof(vis));

    memset(par,0,sizeof(par));

    queue< int > q;

    q.push(1);

    vis[1]=0;



    while(!q.empty()){

        int u=q.front();

        q.pop();



        for(int i=0; i<V[u].size(); i++){

            int v=V[u][i];

            if(vis[v]==0){

                par[v]=u;

                vis[v]=1;

                q.push(v);

            }

        }

    }

}



int main(){

    Fast;

    int a,b,c, i,j, n,m,t, cs=1;



    cin>>n>>m;

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

        cin>>a>>b;

        V[a].push_back(b);

        V[b].push_back(a);

    }

    bfs(1);



    bool flag=true;

    vector < int > pp;

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

        if(par[i]==0){

            flag=false;break;

        }

        pp.push_back(par[i]);

    }

    if(!flag){

        cout<<"No"<<endl;

    }

    else{

        cout<<"Yes"<<endl;

        for(i=0; i<n-1; i++){

            cout<<pp[i]<<endl;

        }

    }





    return 0;

}




// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<string.h>

#include<vector>

#include<deque>

using namespace std;

const int MAX=1e5+10; 

vector<int>v[MAX];

deque<int>q;

int d[MAX];

int vis[MAX];

void bfs()

{

	while(q.size())

	{

		

		int x=q.front();

		q.pop_front();

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

		{

			int y=v[x][i];

			if(!vis[y])

			{

				if(d[y]==999999999)

				d[y]=x;

				q.push_back(y);

				vis[y]=1;

			}

		}

	}

}

int main()

{

	int n,m;

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

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

	{

		int hhn,hn;

		scanf("%d%d",&hhn,&hn);

		v[hhn].push_back(hn);

		v[hn].push_back(hhn);

	} 

	d[1]=0;

	vis[1]=1;

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

	{

		d[i]=999999999;vis[i]=0;

	}

	q.push_back(1);

	bfs();

	int flag=1;

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

	{

		if(d[i]==999999999)

		{

			flag=0;break;

		}

	}

	if(flag)

	{

		cout<<"Yes"<<endl;

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

		cout<<d[i]<<endl;

	}else

	cout<<"No"<<endl;

return 0;

 } 

// Fastest known solution for this problem: