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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int gcd(int a, int b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}
int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
struct Matrix {
  int a[2][2] = {{0, 0}, {0, 0}};
  Matrix operator*(const Matrix &other) {
    Matrix product;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        for (int k = 0; k < 2; k++) {
          product.a[i][k] = product.a[i][k] + (ll)a[i][j] * other.a[j][k];
        }
      }
    }
    return product;
  }
};
int modInverse(int n, int p) { return power(n, p - 2, p); }
vector<int> parent;
vector<int> s;
void make_set(int v) {
  parent[v] = v;
  s[v] = 1;
}
int find_set(int v) {
  if (v == parent[v]) {
    return v;
  }
  return find_set(parent[v]);
}
void union_set(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  // cout<<a<<" "<<b<<'\\n';
  if (a != b) {
    if (s[a] < s[b])
      swap(a, b);

    parent[b] = a;
    s[a] += s[b];
  }
}
int main() {
  // your code goes here
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  parent.resize(n + 1);
  s.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    make_set(i);
  }
  // for(int x:parent)
  // cout<<x<<" ";
  // cout<<'\\n';
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    union_set(a, b);
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, s[i]);
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int gcd(int a, int b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}
int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
struct Matrix {
  int a[2][2] = {{0, 0}, {0, 0}};
  Matrix operator*(const Matrix &other) {
    Matrix product;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        for (int k = 0; k < 2; k++) {
          product.a[i][k] = product.a[i][k] + (ll)a[i][j] * other.a[j][k];
        }
      }
    }
    return product;
  }
};
int modInverse(int n, int p) { return power(n, p - 2, p); }
vector<int> parent;
vector<int> s;
void make_set(int v) {
  parent[v] = v;
  s[v] = 1;
}
int find_set(int v) {
  if (v == parent[v]) {
    return v;
  }
  return parent[v] == find_set(parent[v]);
}
void union_set(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (s[a] < s[b])
      swap(a, b);

    parent[b] = a;
    s[a] += s[b];
    s[b] = s[a];
  }
}
int main() {
  // your code goes here
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  parent.resize(n + 1);
  s.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    make_set(i);
  }
  // for(int x:parent)
  // cout<<x<<" ";
  // cout<<'\\n';
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    union_set(a, b);
    // for(int x:parent)
    // cout<<x<<" ";
    // cout<<'\\n';
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, s[i]);
  }
  cout << ans << '\\n';
  return 0;
}