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

#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define imax INT_MAX
#define imin INT_MIN
#define f(i, a, b) for (long long i = a; i < b; i++)
#define rf(i, a, b) for (long long i = a; i >= b; i--)
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a, n)                                                            \\
  for (ll i = 0; i < n; i++)                                                   \\
    cin >> a[i];
#define output(a, n)                                                           \\
  for (ll i = 0; i < n; i++)                                                   \\
    cout << a[i] << " ";
#define up upper_bound
#define lo lower_bound
#define endl "\\n"
#define mem(a) memset(a, -1, sizeof(a))
#define ll long long
#define umap unordered_map

ll vis[200025] = {0};
set<ll> v[200025];
ll cnt = 0;
void dfs(ll x) {
  if (vis[x] == 1)
    return;

  vis[x] = 1;
  cnt++;
  for (auto p : v[x]) {
    if (vis[p] == 0)
      dfs(p);
  }
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll n, m;

  cin >> n >> m;

  f(i, 0, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].insert(b);
    v[b].insert(a);
  }

  ll ans = 0;
  f(i, 0, n) {
    cnt = 0;
    if (vis[i] == 0) {
      dfs(i);
    }
    ans = max(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define imax INT_MAX
#define imin INT_MIN
#define f(i, a, b) for (long long i = a; i < b; i++)
#define rf(i, a, b) for (long long i = a; i >= b; i--)
#define tc                                                                     \\
  long long t;                                                                 \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a, n)                                                            \\
  for (ll i = 0; i < n; i++)                                                   \\
    cin >> a[i];
#define output(a, n)                                                           \\
  for (ll i = 0; i < n; i++)                                                   \\
    cout << a[i] << " ";
#define up upper_bound
#define lo lower_bound
#define endl "\\n"
#define mem(a) memset(a, -1, sizeof(a))
#define ll long long
#define umap unordered_map

ll vis[100025] = {0};
set<ll> v[100025];
ll cnt = 0;
void dfs(ll x) {
  if (vis[x] == 1)
    return;

  vis[x] = 1;
  cnt++;
  for (auto p : v[x]) {
    if (vis[p] == 0)
      dfs(p);
  }
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll n, m;

  cin >> n >> m;

  f(i, 0, m) {
    ll a, b;
    cin >> a >> b;
    v[a - 1].insert(b - 1);
    v[b - 1].insert(a - 1);
  }

  ll ans = 0;
  f(i, 0, n) {
    cnt = 0;
    if (vis[i] == 0) {
      dfs(i);
    }
    ans = max(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}