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

/**
 * @File   : atcoder.cpp
 * @Author : pasnger
 * @Date   : 29/8/2020, 2:59:47 pm
 */

#include <bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long
#define f(i, a, b) for (int i = a; i < b; i++)
#define rf(i, a, b) for (int i = a; i > b; i--)
const int mod = 1e9 + 7;

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\\n"; }
template <typename T, typename... Args> void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args))
    cerr << ", ";
  DBG(args...);
}

int mul(int x, int y) {
  int res = x * y;
  if (res >= mod)
    res %= mod;
  return res;
}

int add(int x, int y) {
  int res = x + y;
  if (res >= mod)
    res -= mod;
  return res;
}
int sub(int x, int y) {
  int res = x - y;
  if (res < 0)
    res += mod;
  return res;
}

/////////////////////////// GLOBAL ///////////////////////////
const int N = 2e5 + 10;
vector<int> adj[N];
int cnt = 0;
int m;
int visited[N];
/////////////////////////// GLOBAL ///////////////////////////
void dfs(int root, int parent) {
  if (!adj[root].empty()) {
    // deb(root, visited[root], cnt);
    for (auto ele : adj[root]) {
      if (parent != ele && visited[ele] == 0) {
        cnt++;
        visited[ele] = 1;
        dfs(ele, root);
      }
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  int a, b;
  f(i, 0, m) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  fill(visited, visited + N, 0);
  m = 0;
  f(i, 1, n + 1) {
    cnt = 1;
    visited[i] = 1;
    dfs(i, -1);
    m = max(m, cnt);
    // deb(m, cnt);
  }
  cout << m << "\\n";
}

int32_t main() {
#ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  for (int tt = 1; tt <= t; tt++) {
    // cout << "Case #"<<tt<<": ";
    solve();
  }
#ifndef ONLINE_JUDGE
  cerr << "\\nRun Time -> " << (double)(clock() - tStart) / CLOCKS_PER_SEC
       << " sec\\n";
#endif
}


Error: -11

Fixed submission:

/**
 * @File   : atcoder.cpp
 * @Author : pasnger
 * @Date   : 29/8/2020, 2:59:47 pm
 */

#include <bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long
#define f(i, a, b) for (int i = a; i < b; i++)
#define rf(i, a, b) for (int i = a; i > b; i--)
const int mod = 1e9 + 7;

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\\n"; }
template <typename T, typename... Args> void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args))
    cerr << ", ";
  DBG(args...);
}

int mul(int x, int y) {
  int res = x * y;
  if (res >= mod)
    res %= mod;
  return res;
}

int add(int x, int y) {
  int res = x + y;
  if (res >= mod)
    res -= mod;
  return res;
}
int sub(int x, int y) {
  int res = x - y;
  if (res < 0)
    res += mod;
  return res;
}

/////////////////////////// GLOBAL ///////////////////////////
const int N = 1e5 + 10;
vector<int> adj[N];
int cnt = 0;
int m;
int visited[N];
/////////////////////////// GLOBAL ///////////////////////////
void dfs(int root, int parent) {
  if (root) {
    // deb(root, visited[root], cnt);
    if (!adj[root].empty()) {
      for (auto ele : adj[root]) {
        if (parent != ele && visited[ele] == 0) {
          cnt++;
          visited[ele] = 1;
          dfs(ele, root);
        }
      }
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  int a, b;
  f(i, 0, m) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  fill(visited, visited + N, 0);
  m = 0;
  f(i, 1, n + 1) {
    cnt = 1;
    visited[i] = 1;
    dfs(i, -1);
    m = max(m, cnt);
    // deb(m, cnt);
  }
  cout << m << "\\n";
}

int32_t main() {
#ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  for (int tt = 1; tt <= t; tt++) {
    // cout << "Case #"<<tt<<": ";
    solve();
  }
#ifndef ONLINE_JUDGE
  cerr << "\\nRun Time -> " << (double)(clock() - tStart) / CLOCKS_PER_SEC
       << " sec\\n";
#endif
}