Language: C++

/*===================*\
|ID : harryPotter_421  |
|      LANG: C++       |
\*====================*/
#include <iostream>
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define ld  double
#define f(j,m,n) for(lli j=m;j<n;j++)
#define harry ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(n) for(i=0;i<n;i++);
using namespace std;
vector<lli> v[100005];
lli color[100005];
lli pi[100005];




int dfs(lli n)
        {for(lli i=1;i<=n;i++)
            {color[i]=0;
             pi[i]=-1;
             }
          queue<lli> q;
          q.push(1);
          while(!q.empty())
          {
              lli a=q.front();
              for(lli i=0;i<v[a].size();i++)
                  {if(color[v[a][i]]==0)
                       {
                           q.push(v[a][i]);
                           pi[v[a][i]]=a;
                           color[v[a][i]]=1;

                       }

                  }
            q.pop();
          }
        for(lli i=1;i<=n;i++)
            {//cout<<color[i]<<" ";
              if(color[i]==0)
              {
                  cout<<"No";
                  return 0;

              }
            }
            cout<<"Yes"<<endl;
        for(lli i=2;i<=n;i++)
        {
           cout<<pi[i]<<endl;
        }

         }

int main()
   {harry
    lli n,m,a,b;
    cin>>n>>m;


    for(lli i=1;i<=m;i++)
        {cin>>a>>b;

         v[a].pb(b);
         v[b].pb(a);
        }

        dfs(n);
    }







/*===================*\
|ID : harryPotter_421  |
|      LANG: C++       |
\*====================*/
#include <iostream>
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define ld  double
#define f(j,m,n) for(lli j=m;j<n;j++)
#define harry ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(n) for(i=0;i<n;i++);
using namespace std;
vector<lli> v[100005];
lli color[100005];
lli pi[100005];




int dfs(lli n)
        {for(lli i=1;i<=n;i++)
            {color[i]=0;
             pi[i]=-1;
             }
          queue<lli> q;
          q.push(1);
          while(!q.empty())
          {
              lli a=q.front();
              color[a]=1;
              for(lli i=0;i<v[a].size();i++)
                  {if(color[v[a][i]]==0)
                       {
                           q.push(v[a][i]);
                           pi[v[a][i]]=a;
                           color[v[a][i]]=1;

                       }

                  }
            q.pop();
          }
        for(lli i=1;i<=n;i++)
            {//cout<<color[i]<<" ";
              if(color[i]==0)
              {
                  cout<<"No";
                  return 0;

              }
            }
            cout<<"Yes"<<endl;
        for(lli i=2;i<=n;i++)
        {
           cout<<pi[i]<<endl;
        }

         }

int main()
   {harry
    lli n,m,a,b;
    cin>>n>>m;


    for(lli i=1;i<=m;i++)
        {cin>>a>>b;

         v[a].pb(b);
         v[b].pb(a);
        }

        dfs(n);
    }



































Compiler output:
a.cc:95:13: error: redefinition of 'std::vector<long long int> v [100005]'
   95 | vector<lli> v[100005];
      |             ^
a.cc:14:13: note: 'std::vector<long long int> v [100005]' previously declared here
   14 | vector<lli> v[100005];
      |             ^
a.cc:96:5: error: redefinition of 'long long int color [100005]'
   96 | lli color[100005];
      |     ^~~~~
a.cc:15:5: note: 'long long int color [100005]' previously declared here
   15 | lli color[100005];
      |     ^~~~~
a.cc:97:5: error: redefinition of 'long long int pi [100005]'
   97 | lli pi[100005];
      |     ^~
a.cc:16:5: note: 'long long int pi [100005]' previously declared here
   16 | lli pi[100005];
      |     ^~
a.cc:102:5: error: redefinition of 'int dfs(long long int)'
  102 | int dfs(lli n)
      |     ^~~
a.cc:21:5: note: 'int dfs(long long int)' previously defined here
   21 | int dfs(lli n)
      |     ^~~
a.cc:142:5: error: redefinition of 'int main()'
  142 | int main()
      |     ^~~~
a.cc:60:5: note: 'int main()' previously defined here
   60 | int main()
      |     ^~~~
a.cc: In function 'int dfs(long long int)':
a.cc:58:10: warning: control reaches end of non-void function [-Wreturn-type]
   58 |          }
      |          ^
a.cc: In function 'int dfs(long long int)':
a.cc:140:10: warning: control reaches end of non-void function [-Wreturn-type]
  140 |          }
      |          ^