Language: C++

#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
using namespace std;
template <typename T> T Max(T X,T Y){return X>Y?X:Y;}
template <typename T> T Min(T X,T Y){return X<Y?X:Y;}
template <typename T> void chmax(T &X,T Y){X=X>Y?X:Y;return;}
template <typename T> void chmin(T &X,T Y){X=X<Y?X:Y;return;}

const int maxn=100005,maxm=200005;
int n,m;
int len,to[maxm>>1],next[maxm>>1],head[maxn],dist[maxn];
queue<int> q;

inline void addedge(int u,int v)
{
	len++,next[len]=head[u],head[u]=len,to[len]=v;
	return;
}

int main()
{
	memset(dist,-1,sizeof(dist));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	
	dist[1]=0;
	q.push(1);
	while(!q.empty())
	{
		int pos=q.front();
		q.pop();
		for(int i=head[pos];i;i=next[i])
		{
			if(dist[to[i]]!=-1) continue;
			dist[to[i]]=dist[pos]+1;
			q.push(to[i]);
		}
	}
	
	printf("Yes\n");
	for(int pos=2;pos<=n;pos++)
		for(int i=head[pos];i;i=next[i])
			if(dist[to[i]]==dist[pos]-1)
			{
				printf("%d\n",to[i]);
				break;
			}
	return 0;
}

Compiler output:
a.cc: In function 'void addedge(int, int)':
a.cc:21:15: error: reference to 'next' is ambiguous
   21 |         len++,next[len]=head[u],head[u]=len,to[len]=v;
      |               ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:16:21: note:                 'int next [100002]'
   16 | int len,to[maxm>>1],next[maxm>>1],head[maxn],dist[maxn];
      |                     ^~~~
a.cc: In function 'int main()':
a.cc:43:41: error: reference to 'next' is ambiguous
   43 |                 for(int i=head[pos];i;i=next[i])
      |                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:16:21: note:                 'int next [100002]'
   16 | int len,to[maxm>>1],next[maxm>>1],head[maxn],dist[maxn];
      |                     ^~~~
a.cc:53:41: error: reference to 'next' is ambiguous
   53 |                 for(int i=head[pos];i;i=next[i])
      |                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:16:21: note:                 'int next [100002]'
   16 | int len,to[maxm>>1],next[maxm>>1],head[maxn],dist[maxn];
      |                     ^~~~