Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */
struct edge {
  ll from;
  ll to;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  vector<vector<ll>> e(n, vector<ll>(0));
  if (m == 0) {
    cout << 1 << endl;
    return 0;
  }
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }

  vector<bool> f(n, false);
  vector<set<ll>> group(1);
  vector<vector<ll>> g(1, vector<ll>(0));

  REP(i, n) {
    queue<ll> q;
    if (f[i] || e[i].empty())
      continue;
    q.push(i);
    group[group.size() - 1].insert(i);
    g[g.size() - 1].push_back(i);
    while (!q.empty()) {
      for (auto next : e[q.front()]) {
        if (!f[next]) {
          q.push(next);
          group[group.size() - 1].insert(next);
          g[g.size() - 1].push_back(next);
          f[next] = true;
        }
      }
      q.pop();
    }
    group.push_back({});
    g.push_back({});
  }

  ll ans = 0;
  REP(i, group.size()) { ans = max(ans, (ll)group[i].size()); }
  // REP(i, g.size()) { DEBUGS(g[i]); }
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */
struct edge {
  ll from;
  ll to;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  vector<vector<ll>> e(n, vector<ll>(0));
  if (m == 0) {
    cout << 1 << endl;
    return 0;
  }
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }

  vector<bool> f(n, false);
  vector<set<ll>> group(1);
  vector<vector<ll>> g(1, vector<ll>(0));

  REP(i, n) {
    queue<ll> q;
    if (f[i] || e[i].empty())
      continue;
    q.push(i);
    group[group.size() - 1].insert(i);
    g[g.size() - 1].push_back(i);
    while (!q.empty()) {
      for (auto next : e[q.front()]) {
        if (!f[next]) {
          q.push(next);
          group[group.size() - 1].insert(next);
          g[g.size() - 1].push_back(next);
          f[next] = true;
        }
      }
      q.pop();
    }
    group.push_back({});
    g.push_back({});
  }

  ll ans = 0;
  REP(i, m) { ans = max(ans, (ll)group[i].size()); }
  REP(i, g.size()) { DEBUGS(g[i]); }
  cout << ans << endl;
  return 0;
}