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

/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
// focus less on how much problem you should solve within a fixed time and focus
// more on getting the problem solved and learning something from it
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define sedes set<ll, greater<ll>>
#define seasc set<ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x, it) for (auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\\n'
#define all(v) v.begin(), v.end()
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define deba(a) cout << #a << " " << a << endl;
vector<int> adj[1000001];
bool visited[1000001];

void dfs(ll s, ll &ans) {
  // cout << s << " ->";
  visited[s] = true;
  ans++;
  for (ll i = 0; i < adj[s].size(); ++i) {
    if (visited[adj[s][i]] == false)
      dfs(adj[s][i], ans);
  }
}
int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
  freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;

    while (m--) {
      ll x, y;
      cin >> x >> y;
      adj[x].pb(y);
      adj[y].pb(x);
    }
    ll maxi = INT_MIN;
    for (ll i = 1; i <= n; i++) {
      if (visited[i] == false) {
        ll ans = 0;
        dfs(i, ans);
        maxi = max(maxi, ans);
      }
    }
    cout << maxi << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
// focus less on how much problem you should solve within a fixed time and focus
// more on getting the problem solved and learning something from it
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define sedes set<ll, greater<ll>>
#define seasc set<ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x, it) for (auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\\n'
#define all(v) v.begin(), v.end()
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define deba(a) cout << #a << " " << a << endl;
vector<int> adj[100001];
bool visited[100001];

void dfs(ll s, ll &ans) {
  // cout << s << " ->";
  visited[s] = true;
  ans++;
  for (ll i = 0; i < adj[s].size(); ++i) {
    if (visited[adj[s][i]] == false)
      dfs(adj[s][i], ans);
  }
}
int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
  freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;

    while (m--) {
      ll x, y;
      cin >> x >> y;
      adj[x].pb(y);
      adj[y].pb(x);
    }
    ll maxi = INT_MIN;
    for (int i = 1; i <= n; i++) {
      if (visited[i] == false) {
        ll ans = 0;
        dfs(i, ans);
        maxi = max(maxi, ans);
      }
    }
    cout << maxi << endl;
  }
  return 0;
}