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

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define BS binary_search
#define M 1000000007

const long long INF = 1e18;

template <class A, class B>
ostream &operator<<(ostream &os, const pair<A, B> p) {
  return os << "(" << p.first << "," << p.second << ")";
}

void dprint(string s) { cout << endl; }
template <class T, class... U> void dprint(string s, T t, U... u) {
  int w = s.find(',');
  cout << "[" << s.substr(0, w) << ": " << t << "] ";
  dprint(s.substr(w + 1, (int)s.size() - w), u...);
}

#define DEBUG
#ifdef DEBUG
#define dbg(X...) dprint(#X, X)
#else
#define dbg(X...) "KEEP CALM"
#endif

const int N = 200005; // Don't forget to CHANGE this value ACC. TO Q.
set<int> adj[N];
int cnt = 0;
bool vis[N] = {false};
void dfs(int s) {
  vis[s] = true;
  cnt++;
  for (auto it : adj[s]) {
    if (!vis[it])
      dfs(it);
  }
}
int32_t main() {
  IOS;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int T = 1;
  // cin>>T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      adj[a].insert(b);
      adj[b].insert(a);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i);
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define BS binary_search
#define M 1000000007

const long long INF = 1e18;

template <class A, class B>
ostream &operator<<(ostream &os, const pair<A, B> p) {
  return os << "(" << p.first << "," << p.second << ")";
}

void dprint(string s) { cout << endl; }
template <class T, class... U> void dprint(string s, T t, U... u) {
  int w = s.find(',');
  cout << "[" << s.substr(0, w) << ": " << t << "] ";
  dprint(s.substr(w + 1, (int)s.size() - w), u...);
}

#define DEBUG
#ifdef DEBUG
#define dbg(X...) dprint(#X, X)
#else
#define dbg(X...) "KEEP CALM"
#endif

const int N = 100005; // Don't forget to CHANGE this value ACC. TO Q.
set<int> adj[N];
int cnt = 0;
bool vis[N] = {false};
void dfs(int s) {
  vis[s] = true;
  cnt++;
  for (auto it : adj[s]) {
    if (!vis[it])
      dfs(it);
  }
}
int32_t main() {
  IOS;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int T = 1;
  // cin>>T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      adj[a].insert(b);
      adj[b].insert(a);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i);
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}