Problem p02573 (C++)

Buggy submission (status: Runtime Error):
/*
power code taken from geeks for geeks
*/
// cout << setprecision (2) << fixed << 1.2;

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1e18 + 5;
const ll MAX_N = 2e5 + 5;
const ll MODD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
double min(double a, double b) { return a < b ? a : b; }

ll modd(ll a) {
  if (a < 0LL)
    return a * -1LL;
  return a;
}
ld modd(ld a) {
  if (a < 0.0)
    return a * -1.0;
  return a;
}

ll modulo(ll a) { return (a + MODD) % MODD; }

ll power(ll k, ll p) {
  if (p == 0)
    return 1LL;

  ll P = power(k, p / 2LL);
  P = (P * P) % MODD;

  if (p % 2 == 1)
    P = (P * k) % MODD;

  return P;
}

struct p_str {
  ll a, b;
};

// vector<ll> adj[MAX_N];
// bool visited[MAX_N];
ll cnt = 0;
ll _dfs(ll s, vector<ll> adj[], bool visited[]) {
  visited[s] = 1;
  cnt++;
  for (ll ch : adj[s]) {
    if (visited[ch]) {
      continue;
    }
    _dfs(ch, adj, visited);
  }
}

void solve() {
  ll n, m;
  cin >> n >> m;

  vector<ll> adj[n + 5];
  bool visited[n + 5];
  for (ll i = 0; i <= n; i++) {
    visited[i] = 0;
  }

  ll u, v;
  // map<string, int> seen;
  string k1, k2;
  for (ll i = 0; i < m; i++) {
    cin >> u >> v;
    // k1 = to_string(u) + "|" + to_string(v);
    // k1 = to_string(v) + "|" + to_string(u);
    // if(seen[k1]) {
    //     continue;
    // }
    adj[u].push_back(v);
    adj[v].push_back(u);
    // seen[k1] = 1;
    // seen[k2] = 1;
  }

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      cnt = 0;
      _dfs(i, adj, visited);
      ans = max(ans, cnt);

      // cout << "i " << i << " c " << c << endl;
    }
  }
  cout << ans << endl;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll t = 1;

  // cin>>t;

  while (t--) {

    solve();
  }

  return 0;
}

Fixed submission:
/*
power code taken from geeks for geeks
*/
// cout << setprecision (2) << fixed << 1.2;

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1e18 + 5;
const ll MAX_N = 2e5 + 5;
const ll MODD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
double min(double a, double b) { return a < b ? a : b; }

ll modd(ll a) {
  if (a < 0LL)
    return a * -1LL;
  return a;
}
ld modd(ld a) {
  if (a < 0.0)
    return a * -1.0;
  return a;
}

ll modulo(ll a) { return (a + MODD) % MODD; }

ll power(ll k, ll p) {
  if (p == 0)
    return 1LL;

  ll P = power(k, p / 2LL);
  P = (P * P) % MODD;

  if (p % 2 == 1)
    P = (P * k) % MODD;

  return P;
}

struct p_str {
  ll a, b;
};

// vector<ll> adj[MAX_N];
// bool visited[MAX_N];
ll cnt = 0;
void _dfs(ll s, vector<ll> adj[], bool visited[]) {
  visited[s] = 1;
  cnt++;
  for (ll ch : adj[s]) {
    if (visited[ch]) {
      continue;
    }
    _dfs(ch, adj, visited);
  }
}

void solve() {
  ll n, m;
  cin >> n >> m;

  vector<ll> adj[n + 5];
  bool visited[n + 5];
  for (ll i = 0; i <= n; i++) {
    visited[i] = 0;
  }

  ll u, v;
  // map<string, int> seen;
  string k1, k2;
  for (ll i = 0; i < m; i++) {
    cin >> u >> v;
    // k1 = to_string(u) + "|" + to_string(v);
    // k1 = to_string(v) + "|" + to_string(u);
    // if(seen[k1]) {
    //     continue;
    // }
    adj[u].push_back(v);
    adj[v].push_back(u);
    // seen[k1] = 1;
    // seen[k2] = 1;
  }

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      cnt = 0;
      _dfs(i, adj, visited);
      ans = max(ans, cnt);

      // cout << "i " << i << " c " << c << endl;
    }
  }
  cout << ans << endl;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll t = 1;

  // cin>>t;

  while (t--) {

    solve();
  }

  return 0;
}