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

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mex = 200005;
#define ll long long
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define fo(i, a, n) for (int i = a; i < n; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(), x.end()
#define sci(x) scanf("%d", &x);
#define scc(x) scanf("%c", &x);
#define scs(x) scanf("%s", x);
#define debug(arr, n)                                                          \\
  for (int i = 0; i < n; i++)                                                  \\
    printf("%d ", arr[i]);
#define sz(x) x.size()
#define loop(x) for (auto it = x.begin(); it != x.end(); it++)

ll int power(ll int a, ll int b) {
  ll int ans = 1, f = a;
  while (b) {
    if (b & 1ll)
      ans = (ans * f) % mod;
    b = b >> 1ll;
    f = (f * f) % mod;
  }
  return ans;
}

vector<int> v[mex];
int vis[mex], cnt = 0;
void dfs(int n) {
  vis[n] = 1;
  cnt++;
  fo(i, 0, sz(v[n])) if (vis[v[n][i]] == 0) dfs(v[n][i]);
}
int main() {

  int n, m;
  cin >> n >> m;
  fo(i, 0, m) {
    int a, b;
    cin >> a >> b;
    v[a].pb(b);
    v[b].pb(a);
  }
  int ans = 0;
  fo(i, 1, n + 1) {
    if (vis[i] == 0) {
      dfs(i);
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mex = 100005;
#define ll long long
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define fo(i, a, n) for (int i = a; i < n; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(), x.end()
#define sci(x) scanf("%d", &x);
#define scc(x) scanf("%c", &x);
#define scs(x) scanf("%s", x);
#define debug(arr, n)                                                          \\
  for (int i = 0; i < n; i++)                                                  \\
    printf("%d ", arr[i]);
#define sz(x) x.size()
#define loop(x) for (auto it = x.begin(); it != x.end(); it++)

ll int power(ll int a, ll int b) {
  ll int ans = 1, f = a;
  while (b) {
    if (b & 1ll)
      ans = (ans * f) % mod;
    b = b >> 1ll;
    f = (f * f) % mod;
  }
  return ans;
}

vector<int> v[mex];
int vis[mex], cnt = 0;
void dfs(int n) {
  vis[n] = 1;
  cnt++;
  fo(i, 0, sz(v[n])) if (vis[v[n][i]] == 0) dfs(v[n][i]);
}
int main() {

  int n, m;
  cin >> n >> m;
  fo(i, 0, m) {
    int a, b;
    cin >> a >> b;
    v[a].pb(b);
    v[b].pb(a);
  }
  int ans = 0;
  fo(i, 1, n + 1) {
    if (vis[i] == 0) {
      dfs(i);
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  cout << ans << endl;
}