Language: C++


// Problem : D - .. (Double Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
int n,m;
vector<int> adj[maxn];
pp visit[maxn];
void dfs(int curr,int par,int ht)
{
	visit[curr]={par,ht};
	for(auto x:adj[curr])
	{
		if(visit[x].ff==0)
		{
			dfs(x,curr,ht+1);
		}
		else{
			if(visit[x].ss >= ht+1)
			{
				visit[x]={curr,ht+1};
			}
		}
	}
}
void solve()
{
	cin >> n >> m;
	rep(i,0,m)
	{
		int x,y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs(1,-1,0);
	repe(i,2,n)
	{
		if(visit[i].ff==0)
		{
			cout << "No";
			return;
		}
	}
	cout << "Yes"<<"\n";
	repe(i,2,n)
	{
		cout << visit[i].ff <<"\n";
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void dfs(long long int, long long int, long long int)':
a.cc:30:9: error: reference to 'visit' is ambiguous
   30 |         visit[curr]={par,ht};
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:9:
/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:27:4: note:                 'std::pair<long long int, long long int> visit [100005]'
   27 | pp visit[maxn];
      |    ^~~~~
a.cc:33:20: error: reference to 'visit' is ambiguous
   33 |                 if(visit[x].ff==0)
      |                    ^~~~~
/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:27:4: note:                 'std::pair<long long int, long long int> visit [100005]'
   27 | pp visit[maxn];
      |    ^~~~~
a.cc:38:28: error: reference to 'visit' is ambiguous
   38 |                         if(visit[x].ss >= ht+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:27:4: note:                 'std::pair<long long int, long long int> visit [100005]'
   27 | pp visit[maxn];
      |    ^~~~~
a.cc:40:33: error: reference to 'visit' is ambiguous
   40 |                                 visit[x]={curr,ht+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:27:4: note:                 'std::pair<long long int, long long int> visit [100005]'
   27 | pp visit[maxn];
      |    ^~~~~
a.cc: In function 'void solve()':
a.cc:58:20: error: reference to 'visit' is ambiguous
   58 |                 if(visit[i].ff==0)
      |                    ^~~~~
/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:27:4: note:                 'std::pair<long long int, long long int> visit [100005]'
   27 | pp visit[maxn];
      |    ^~~~~
a.cc:67:25: error: reference to 'visit' is ambiguous
   67 |                 cout << visit[i].ff <<"\n";
      |                         ^~~~~
/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:27:4: note:                 'std::pair<long long int, long long int> visit [100005]'
   27 | pp visit[maxn];
      |    ^~~~~