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

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X)                                                                  \\
  ({                                                                           \\
    if (1)                                                                     \\
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \\
  })
ll N, M;

vvl graph;
vector<bool> seen;

ll sizeDFS(ll node) {
  // cout << node << endl;
  seen[node] = true;
  ll ret = 1;
  FOR(i, 0, graph[node].size()) {
    if (seen[graph[node][i]])
      continue;
    ret += sizeDFS(graph[node][i]);
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;

  graph = vvl(N + 10, vl());
  set<pll> friends;

  FOR(i, 0, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    if (friends.find(mp(a, b)) != friends.end())
      continue;
    friends.insert(mp(a, b));
    friends.insert(mp(b, a));
    graph[a].pb(b);
    graph[b].pb(a);
  }
  seen = vector<bool>(N, false);
  ll sol = 1;
  FOR(j, 0, N) {
    if (seen[j])
      continue;
    sol = max(sol, sizeDFS(j));
  }

  cout << sol << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X)                                                                  \\
  ({                                                                           \\
    if (1)                                                                     \\
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \\
  })
ll N, M;

vvl graph;
vvl friends;
vector<bool> seen;

ll sizeDFS(ll node) {
  // cout << node << endl;
  cout << node << endl;
  seen[node] = true;
  ll ret = 1;
  FOR(i, 0, graph[node].size()) {
    if (seen[graph[node][i]])
      continue;
    ret += sizeDFS(graph[node][i]);
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;

  graph = vvl(N, vl());
  friends = vvl(N, vl(N, 0));

  FOR(i, 0, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    if (friends[a][b] == 1)
      continue;
    friends[a][b] = 1;
    friends[b][a] = 1;
    graph[a].pb(b);
    graph[b].pb(a);
  }
  seen = vector<bool>(N, false);
  ll sol = 1;
  FOR(j, 0, N) {
    if (seen[j])
      continue;
    sol = max(sol, sizeDFS(j));
  }

  cout << sol << endl;
}