Language: C++

#include<iostream>
#include<string.h>
#include<algorithm>
#include<utility>
#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;
   for(int k=0;k<(n-1);k++)
   {
     //Find the unvisited vertex with minimum weight
    int requiredVertex = -1;
    for(int i=0;i<n;i++)
    {
        if(visited.count(i)==0)
        {
            if(requiredVertex==-1)
            {
                requiredVertex = i;
            }
            else
            {
                if(distannce[requiredVertex]>distannce[i])
                {
                    requiredVertex =i;
                }
            }
        }
    }
    //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)
        {
            if(distannce[currentVertex]>distannce[requiredVertex] + 1)
            {
                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:79:20: error: 'INT_MAX' was not declared in this scope
   79 |     distannce[i] = INT_MAX;
      |                    ^~~~~~~
a.cc:9:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    8 | #include<set>
  +++ |+#include <climits>
    9 | using namespace std;
a.cc:125:22: error: 'INT_MAX' was not declared in this scope
  125 |     if(distannce[i]==INT_MAX)
      |                      ^~~~~~~
a.cc:125:22: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'