Language: C++

include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<vector<int>> Graph;
Graph G(100010);
vector<int> par(100010);
int room[10010] = { };
void init(int N) { //最初は全てが根であるとして初期化
  for (int i = 0; i < N; i++)
    par[i] = i;
}

int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
  if (par[x] == x)
    return x;
  return par[x] = root(par[x]);
}

void unite(int x, int y) { // xとyの木を併合
  int rx = root(x); //xの根をrx
  int ry = root(y); //yの根をry
  if (rx == ry)
    return; //xとyの根が同じ(=同じ木にある)時はそのまま
  if (ry < rx) {
    par[rx] = ry;
  } else {
    par[ry] = rx;
  }
}

bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
  int rx = root(x);
  int ry = root(y);
  return rx == ry;
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  init(n + 1);
  rep(i,m)
  {
    cin >> a >> b;
    unite(a, b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 2; i <= n; i++) {
    if (!same(1, i)) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes" << endl;
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    rep(i,G[c].size())
    {
      if (room[G[c][i]] == 0) {
        room[G[c][i]] = c;
        q.push(G[c][i]);
      }
    }
  }
  for (int i = 2; i <= n; i++)
    cout << room[i] << endl;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include<bits/stdc++.h>
      | ^~~~~~~
a.cc:5:9: error: 'vector' does not name a type
    5 | typedef vector<vector<int>> Graph;
      |         ^~~~~~
a.cc:6:1: error: 'Graph' does not name a type
    6 | Graph G(100010);
      | ^~~~~
a.cc:7:1: error: 'vector' does not name a type
    7 | vector<int> par(100010);
      | ^~~~~~
a.cc: In function 'void init(int)':
a.cc:11:5: error: 'par' was not declared in this scope
   11 |     par[i] = i;
      |     ^~~
a.cc: In function 'int root(int)':
a.cc:15:7: error: 'par' was not declared in this scope
   15 |   if (par[x] == x)
      |       ^~~
a.cc:17:10: error: 'par' was not declared in this scope
   17 |   return par[x] = root(par[x]);
      |          ^~~
a.cc: In function 'void unite(int, int)':
a.cc:26:5: error: 'par' was not declared in this scope
   26 |     par[rx] = ry;
      |     ^~~
a.cc:28:5: error: 'par' was not declared in this scope
   28 |     par[ry] = rx;
      |     ^~~
a.cc: In function 'int main()':
a.cc:39:3: error: 'cin' was not declared in this scope
   39 |   cin >> n >> m;
      |   ^~~
a.cc:45:5: error: 'G' was not declared in this scope
   45 |     G[a].push_back(b);
      |     ^
a.cc:50:7: error: 'cout' was not declared in this scope
   50 |       cout << "No";
      |       ^~~~
a.cc:54:3: error: 'cout' was not declared in this scope
   54 |   cout << "Yes" << endl;
      |   ^~~~
a.cc:54:20: error: 'endl' was not declared in this scope
   54 |   cout << "Yes" << endl;
      |                    ^~~~
a.cc:55:3: error: 'queue' was not declared in this scope
   55 |   queue<int> q;
      |   ^~~~~
a.cc:55:9: error: expected primary-expression before 'int'
   55 |   queue<int> q;
      |         ^~~
a.cc:56:3: error: 'q' was not declared in this scope
   56 |   q.push(1);
      |   ^
a.cc:60:11: error: 'G' was not declared in this scope
   60 |     rep(i,G[c].size())
      |           ^
a.cc:3:45: note: in definition of macro 'rep'
    3 | #define rep(i, n) for (int i = 0; i < (int)(n); ++i)
      |                                             ^