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

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// #include<boost/multiprecision/cpp_dec_float.hpp>
// namespace mp=boost::multiprecision;
// #define mulint mp::cpp_int
// #define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
constexpr int MOD = 1000000007;
// constexpr int MOD=998244353;
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\\n"
#define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 2e5 + 5;
// struct edge{lint to,num;};

lint par[200500];    // MAX_N
lint ufsize[200050]; // MAX_N

void init(lint x) { rep(i, x) par[i] = i, ufsize[i] = 1; }

lint root(lint x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = root(par[x]);
}

bool same(lint x, lint y) { return root(x) == root(y); }

void unite(lint x, lint y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;
  lint s = ufsize[x] + ufsize[y];
  ufsize[x] = s, ufsize[y] = s;
  par[x] = y;
}

lint size(lint x) { return ufsize[root(x)]; }

int main(void) {
  int N, M;
  cin >> N >> M;
  init(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    unite(a, b);
  }
  lint ans = -INF;
  rep(i, N) ans = max(ans, size(i));
  cout << ans << endl;
}

Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// #include<boost/multiprecision/cpp_dec_float.hpp>
// namespace mp=boost::multiprecision;
// #define mulint mp::cpp_int
// #define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
constexpr int MOD = 1000000007;
// constexpr int MOD=998244353;
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\\n"
#define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 2e5 + 5;
// struct edge{lint to,num;};

lint par[100500];    // MAX_N
lint ufsize[100050]; // MAX_N

void init(lint x) { rep(i, x) par[i] = i, ufsize[i] = 1; }

lint root(lint x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = root(par[x]);
}

bool same(lint x, lint y) { return root(x) == root(y); }

void unite(lint x, lint y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;
  lint s = ufsize[x] + ufsize[y];
  ufsize[x] = s, ufsize[y] = s;
  par[x] = y;
}

lint size(lint x) { return ufsize[root(x)]; }

int main(void) {
  int N, M;
  cin >> N >> M;
  init(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    unite(a, b);
  }
  lint ans = -INF;
  rep(i, N) ans = max(ans, size(i));
  cout << ans << endl;
}