Language: C++

    #include<bits/stdc++.h>
    #define pb push_back
    #define ll long long
    #define pii pair<int,int>
    using namespace std;
    vector <vector<int>> v(200005);
    int visit[200005];
    int level[200005];
    int x=0;
    void bfs(int n)
    {
    	queue <pii> q;
    	q.push({n,0});
    	while(!q.empty())
    	{
    		// cout<<"hi";
    		pii y=q.front();
    		q.pop();
    		// cout<<y.first<<endl;
    		x++;
    		for (int i = 0; i < v[y.first].size(); ++i)
    		{
    			if(visit[v[y.first][i]]==false)
    			{
    				visit[v[y.first][i]]=1;
    				level[v[y.first][i]]=y.second+1;
    				q.push({v[y.first][i],level[v[y.first][i]]});
    			}
    		}

    	}
    }
    int power(int x, unsigned int y, unsigned int m) 
	{ 
    	if (y == 0) 
        	return 1; 
    	int p = power(x, y/2, m) % m; 
    	p = (p * p) % m; 
  
 	   return (y%2 == 0)? p : (x * p) % m; 
	} 
	int modInverse(int a, int m) 
	{   
    	return power(a, m-2, m);
	}
    signed main()
    {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll t=1;
    	// cin >> t;
    	/*SAARE INPUTS LENA*/
    	/*VARIABLES KI RANGE DEKHLENA*/
    	while(t-->0)
    	{
    		ll n=0,m=0;
    		cin>>n>>m;
    		ll a=0,b=0;
    		for (int i = 0; i < m; ++i)
    		{
    			// cout<<i<<endl;
    			cin>>a>>b;
    			v[a].pb(b);
    			v[b].pb(a);
    		}
    		for (int i = 0; i <=n; ++i)
    		{
    			visit[i]=0;
    		}
    		visit[1]=true;
    		// x++;
    		bfs(1);
    		if(x!=n)
    			cout<<"No";
    		else
    		{
    			cout<<"Yes"<<endl;
    			for (int i = 2; i <=n; ++i)
    			{
    				cout<<level[i]<<endl;
    			}
    		}
    	}
    	return 0;
    }

Compiler output:
a.cc: In function 'void bfs(int)':
a.cc:23:28: error: reference to 'visit' is ambiguous
   23 |                         if(visit[v[y.first][i]]==false)
      |                            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc: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:7:9: note:                 'int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~
a.cc:25:33: error: reference to 'visit' is ambiguous
   25 |                                 visit[v[y.first][i]]=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:7:9: note:                 'int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~
a.cc: In function 'int main()':
a.cc:67:25: error: reference to 'visit' is ambiguous
   67 |                         visit[i]=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:7:9: note:                 'int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~
a.cc:69:17: error: reference to 'visit' is ambiguous
   69 |                 visit[1]=true;
      |                 ^~~~~
/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:7:9: note:                 'int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~