Language: C++

#include<iostream>
#include<string.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<unordered_map>
#include<vector>
#include<math.h>
#include<set>
using namespace std;
// bool findPossibleOrNot(int** edges,int n,int* visited,int currentIndex,int count1,int count2,int count3,int n1,int n2,int n3,int currentColour)
// {
//     visited[currentIndex] = currentColour;
//     if(currentColour==1)
//     {
//         if(count2)
//     }
//     else if(currentColour==2)
//     {

//     }
//     else
//     {

//     }
// }
// int main()
// {
   //  int n;
   //  cin>>*edges = new int*[n];
   //  for(int i=0;i<n;i++)
   //  {
   //      edges[i] = new int[n]{0};
   //  }
   //  int e;
   //  cin>>e;
   //  while(e--)
   //  {
   //      int x,y; 
   //      cin>>x>>y;
   //      edges[x][y] = 1;
   //      edges[y][x] = 1;
   // }
   // int n1,n2,n3;
   // cin>>n1>>n2>>n3;
   // int *visited = new int[n]{0};
   // bool ans = findPossibleOrNot(edges,n,0,visited,0,0,0,n1,n2,n3,1)<<endl;
   // if(ans==true){
   //  cout<<"YES"<<endl;
   //  for(int i=0;i<n;i++)
   //  {
   //      cout<<visited[i]<<" ";
   //  }
   // }
   // else
   // {
   //  cout<<"NO"<<endl;
   // }
// }
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
    int n;
    cin>>n;
    int e;
    cin>>e;
    vector<int> v[n]; 
    while(e--)
    {
        int x,y; 
        cin>>x>>y;
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
   }
   unordered_map<int,int> visited;
   int* distannce = new int[n];
   for(int i=1;i<n;i++)
   {
    distannce[i] = INT_MAX;
   }
   int* parent = new int[n];
   for(int i=0;i<n;i++)
   {
    parent[i] = 0;
   }
   distannce[0] = 0;
   queue<int> q;
   q.push(0);
   while(!q.empty())
   {
     //Find the unvisited vertex with minimum weight
    int requiredVertex = q.front();
    q.pop();

    //Now explore all the unvisited vertices of this required vertex
    for(int i=0;i<v[requiredVertex].size();i++)
    {
        int currentVertex = v[requiredVertex][i];
        if(visited.count(currentVertex)==0)
        {
            q.push(currentVertex);
            if(distannce[currentVertex]>=distannce[requiredVertex] + 1)
            {
                if(distannce[currentVertex]==distannce[requiredVertex] + 1  && parent[currentVertex]>requiredVertex)
                {
                    parent[currentVertex] = requiredVertex;
                    continue;
                }
                distannce[currentVertex] = distannce[requiredVertex] + 1;
                parent[currentVertex] = requiredVertex;
            }
        }
    }
    visited[requiredVertex]++;
   }
   for(int i=1;i<n;i++)
   {
    if(distannce[i]==INT_MAX)
    {
        cout<<"No"<<endl;
        return 0;
    }
   }
   cout<<"Yes"<<endl;
   for(int i=1;i<n;i++)
   {
    cout<<parent[i]+1<<endl;
   }

}

Compiler output:
a.cc: In function 'int main()':
a.cc:80:20: error: 'INT_MAX' was not declared in this scope
   80 |     distannce[i] = INT_MAX;
      |                    ^~~~~~~
a.cc:10:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    9 | #include<set>
  +++ |+#include <climits>
   10 | using namespace std;
a.cc:119:22: error: 'INT_MAX' was not declared in this scope
  119 |     if(distannce[i]==INT_MAX)
      |                      ^~~~~~~
a.cc:119:22: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'