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

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\\n'
#define dbg(x) cout << #x << ": " << x << endl
#define clr(x, v) memset(x, v, sizeof(x))
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 2e5 + 5;

int parent[MAXN], sz[MAXN];

void make_set() {
  iota(parent, parent + MAXN, 0);
  fill(sz, sz + MAXN, 1);
}

int find_set(int v) {
  if (v == parent[v])
    return v;
  else
    return parent[v] = find_set(parent[v]);
}

bool union_set(int a, int b) {
  a = find_set(a), b = find_set(b);
  if (sz[a] < sz[b])
    swap(a, b);
  if (a != b)
    parent[b] = a, sz[a] += sz[b];
  return a != b;
}

void cp() {
  int n, m;
  cin >> n >> m;
  make_set();
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    union_set(u, v);
  }
  int mx = 1;
  for (int i = 0; i < n; i++)
    if (i == find_set(i))
      mx = max(mx, sz[i]);
  cout << mx;
}

int main() {
  FASTIO;
  int t;
  t = 1;
  // cin >> t;
  while (t--) {
    cp();
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\\n'
#define dbg(x) cout << #x << ": " << x << endl
#define clr(x, v) memset(x, v, sizeof(x))
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 2e5 + 5;

int parent[MAXN], sz[MAXN];

void make_set() {
  iota(parent, parent + MAXN, 0);
  fill(sz, sz + MAXN, 1);
}

int find_set(int v) {
  if (v == parent[v])
    return v;
  else
    return parent[v] = find_set(parent[v]);
}

bool union_set(int a, int b) {
  a = find_set(a), b = find_set(b);
  if (sz[a] < sz[b])
    swap(a, b);
  if (a != b)
    parent[b] = a, sz[a] += sz[b];
}

void cp() {
  int n, m;
  cin >> n >> m;
  make_set();
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    union_set(u, v);
  }
  int mx = 1;
  for (int i = 0; i < n; i++)
    if (i == find_set(i))
      mx = max(mx, sz[i]);
  cout << mx;
}

int main() {
  FASTIO;
  int t;
  t = 1;
  // cin >> t;
  while (t--) {
    cp();
  }
  return 0;
}