Language: C++

/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

const int sz = 1e6+5;
int parent[sz];
bool visit[sz];
vi adj[sz];

int main() {
	memset(parent, -1, sizeof parent);
	int n, m;
	sci(n), sci(m);
	for (int i = 0; i < m; ++i) {
		int u, v;
		sci(u), sci(v);
		adj[u].pb(v); adj[v].pb(u);
	}
	queue<pi> q;
	q.push({1, -1});
	while (!q.empty()) {
		int curr, par;
		tie(curr, par) = q.front();
		q.pop();
		if (!visit[curr]) {
			visit[curr] = 1;
			parent[curr] = par;
			for (auto &nx : adj[curr]) {
				if (!visit[nx]) {
					q.push({nx, curr});
				}
			}
		}
	}
	for (int i = 2; i <= n; ++i) {
		if (parent[i] == -1) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	for (int i = 2; i <= n; ++i) {
		printf("%d\n", parent[i]);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:76:22: error: reference to 'visit' is ambiguous
   76 |                 if (!visit[curr]) {
      |                      ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:3:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:58:6: note:                 'bool visit [1000005]'
   58 | bool visit[sz];
      |      ^~~~~
a.cc:77:25: error: reference to 'visit' is ambiguous
   77 |                         visit[curr] = 1;
      |                         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:58:6: note:                 'bool visit [1000005]'
   58 | bool visit[sz];
      |      ^~~~~
a.cc:80:38: error: reference to 'visit' is ambiguous
   80 |                                 if (!visit[nx]) {
      |                                      ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:58:6: note:                 'bool visit [1000005]'
   58 | bool visit[sz];
      |      ^~~~~