Problem p02678 (C++)

Buggy submission (status: Runtime Error):
/*
    @uthor: Amit Kumar
    user --> CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank:
   dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout << "\Case #" << x << "\:"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll popcount(ll num) {
  num = num - ((num >> 1) & 0x55555555);
  num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
  return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

void virus() {
  ll nodes, vertices;
  cin >> nodes >> vertices;

  vector<ll> adj[vertices + 1];

  for (auto i = 0; i < vertices; i++) {
    ll scr, dest;
    cin >> scr >> dest;
    adj[scr].push_back(dest);
    adj[dest].push_back(scr);
  }

  queue<ll> q;
  vector<bool> visited(nodes + 1);
  vector<ll> res(nodes + 1);

  q.push(1);
  visited[1] = true;
  while (!q.empty()) {
    ll val = q.front();
    q.pop();
    for (auto i : adj[val]) {
      if (!visited[i]) {
        q.push(i);
        visited[i] = true;
        res[i] = val;
      }
    }
  }
  cout << "Yes\n";
  for (auto i = 2; i <= nodes; i++)
    cout << res[i] << "\n";
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

  ll t = 1;
  // cin>>t;
  while (t--) {
    auto start = high_resolution_clock::now();
    virus();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    // cout << "Time: "<<duration.count()<<endl;
    // your code goes here
  }
  return 0;
}

Fixed submission:
/*
    @uthor: Amit Kumar
    user --> CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank:
   dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout << "\Case #" << x << "\:"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll popcount(ll num) {
  num = num - ((num >> 1) & 0x55555555);
  num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
  return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

void virus() {
  ll nodes, vertices;
  cin >> nodes >> vertices;

  vector<ll> adj[nodes + 1];

  for (auto i = 0; i < vertices; i++) {
    ll scr, dest;
    cin >> scr >> dest;
    adj[scr].push_back(dest);
    adj[dest].push_back(scr);
  }

  queue<ll> q;
  vector<bool> visited(nodes + 1);
  vector<ll> res(nodes + 1);

  q.push(1);
  visited[1] = true;
  while (!q.empty()) {
    ll val = q.front();
    q.pop();
    for (auto i : adj[val]) {
      if (!visited[i]) {
        q.push(i);
        visited[i] = true;
        res[i] = val;
      }
    }
  }
  cout << "Yes\n";
  for (auto i = 2; i <= nodes; i++)
    cout << res[i] << "\n";
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

  ll t = 1;
  // cin>>t;
  while (t--) {
    auto start = high_resolution_clock::now();
    virus();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    // cout << "Time: "<<duration.count()<<endl;
    // your code goes here
  }
  return 0;
}