alexjercan/bugnet huggingface dataset:
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

const ll MAX_N = 200200;

ll par[MAX_N];
ll u_rank[MAX_N];

void init(ll n) {
  for (ll i = 0; i < n; i++) {
    par[i] = i;
    u_rank[i] = 0;
  }
}

ll find(ll x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(ll x, ll y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (u_rank[x] < u_rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (u_rank[x] == u_rank[y])
      u_rank[x]++;
  }
}

bool same(ll x, ll y) { return find(x) == find(y); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll i, j, k, l;

  ll N, M;
  cin >> N >> M;
  init(N);
  vll A, B;
  for (i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    A.push_back(a);
    B.push_back(b);
    unite(a, b);
  }
  vll counts(N, 0);
  for (i = 0; i < N; i++) {
    counts[find(i)]++;
  }
  ll ans = 0;
  for (i = 0; i < N; i++) {
    ans = max(ans, counts[i]);
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

const ll MAX_N = 100100;

ll par[MAX_N];
ll u_rank[MAX_N];

void init(ll n) {
  for (ll i = 0; i < n; i++) {
    par[i] = i;
    u_rank[i] = 0;
  }
}

ll find(ll x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(ll x, ll y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (u_rank[x] < u_rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (u_rank[x] == u_rank[y])
      u_rank[x]++;
  }
}

bool same(ll x, ll y) { return find(x) == find(y); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll i, j, k, l;

  ll N, M;
  cin >> N >> M;
  init(N);
  vll A, B;
  for (i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    A.push_back(a);
    B.push_back(b);
    unite(a, b);
  }
  vll counts(N, 0);
  for (i = 0; i < N; i++) {
    counts[par[i]]++;
  }
  ll ans = 0;
  for (i = 0; i < N; i++) {
    ans = max(ans, counts[i]);
  }
  cout << ans << endl;

  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> f(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    f[a].push_back(b);
    f[b].push_back(a);
  }
  vector<int> g(n + 1, -1);
  int id = 0;
  for (int i = 1; i <= n; i++) {
    if (g[i] != -1)
      continue;
    stack<int> s;
    s.push(i);
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      for (int j : f[t]) {
        if (g[j] != -1)
          continue;
        g[j] = id;
        s.push(j);
      }
    }
    id += 1;
  }
  vector<int> ans(id);
  for (int i : g) {
    if (i < 0)
      continue;
    ans[i] += 1;
  }
  int mx = 1;
  for (int i : ans) {
    mx = max(mx, i);
  }
  cout << mx << endl;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> f(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    f[a].push_back(b);
    f[b].push_back(a);
  }
  vector<int> g(n + 1, -1);
  int id = 0;
  for (int i = 1; i <= n; i++) {
    if (g[i] != -1)
      continue;
    stack<int> s;
    s.push(i);
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      for (int j : f[t]) {
        if (g[j] != -1)
          continue;
        g[j] = id;
        s.push(j);
      }
    }
    id += 1;
  }
  vector<int> ans(id);
  for (int id : g) {
    ans[id] += 1;
  }
  int mx = 0;
  for (int i : ans) {
    mx = max(mx, i);
  }
  cout << mx << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

#define pb push_back
#define es erase
#define in insert

#define pii pair<ll, ll>
#define ll long long
#define lb long double

#define ioss                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define m_p(i, j) make_pair(i, j)
#define mem(a, x) memset(a, x, sizeof(a))
#define endl "\\n"
#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll maxn = 6e5 + 7;
ll n, fa[maxn], m, num[maxn];
ll ifind(ll x) {
  if (x == fa[x])
    return x;
  return fa[x] = ifind(fa[x]);
}
void cmb(ll x, ll y) {
  ll fx = ifind(x), fy = ifind(y);
  if (fx != fy) {
    fa[fx] = fy;
    num[fy] += num[fx];
  }
}
int main() {
  cin >> n >> m;
  for (ll i = 1; i <= n; i++) {
    fa[i] = i;
    num[i] = 1;
  }
  for (ll i = 1; i <= m; i++) {
    ll x, y;
    cin >> x >> y;
    cmb(x, y);
  }
  cout << *max_element(num + 1, num + 1 + n) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

#define pb push_back
#define es erase
#define in insert

#define pii pair<ll, ll>
#define ll long long
#define lb long double

#define ioss                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define m_p(i, j) make_pair(i, j)
#define mem(a, x) memset(a, x, sizeof(a))
#define endl "\\n"
#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll maxn = 6e5 + 7;
ll n, a[maxn], fa[maxn], m, num[maxn];
int ifind(int x) {
  if (x == fa[x])
    return x;
  return fa[x] = ifind(fa[x]);
}
int cmb(int x, int y) {
  int fx = ifind(x), fy = ifind(y);
  if (fx != fy) {
    fa[fx] = fy;
    num[fy] += num[fx];
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    num[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    cmb(x, y);
  }
  ll ma = 0;
  for (int i = 1; i <= n; i++) {
    ma = max(ma, num[i]);
  }
  cout << ma << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int root[200010];    // root[i]=i's parent
int element[200010]; // element[i]=i's group's element
// element[find(i)] is better

void init(int n) {
  for (int i = 0; i < n; i++)
    root[i] = i, element[i] = 1;
} // reset
int find(int x) {
  if (root[x] == x) {
    return x;
  } else {
    return root[x] = find(root[x]);
  }
} // search x's parent
bool same(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  root[x] = y;
  element[y] += element[x];
} // x"->"y

int main() {
  int n, m;
  cin >> n >> m;
  init(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    unite(a, b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, element[i]);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int root[100010];    // root[i]=i's parent
int element[100010]; // element[i]=i's group's element
// element[find(i)] is better

void init(int n) {
  for (int i = 0; i < n; i++)
    root[i] = i, element[i] = 1;
} // reset
int find(int x) {
  if (root[x] == x) {
    return x;
  } else {
    return root[x] = find(root[x]);
  }
} // search x's parent
bool same(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  root[x] = y;
  element[y] += element[x];
} // x"->"y

int main() {
  int n, m;
  cin >> n >> m;
  init(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    unite(a, b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, element[i]);
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
void dfs(int v, int &size) {
  size++;
  vis[v] = 1;
  for (int u : g[v]) {
    if (!vis[u]) {
      dfs(u, size);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc = 1;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      g[u].pb(v);
      g[v].pb(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        int size = 0;
        dfs(i, size);
        ans = max(ans, size);
      }
    }
    cout << ans << '\\n';
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
int dfs(int v, int p, int &size) {
  size++;
  vis[v] = 1;
  for (int u : g[v]) {
    if (!vis[u]) {
      dfs(u, v, size);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc = 1;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      g[u].pb(v);
      g[v].pb(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        int size = 0;
        dfs(i, 0, size);
        ans = max(ans, size);
      }
    }
    cout << ans << '\\n';
  }
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n - 1; i >= (int)(k); i--)
#define all(x) (x).begin(), (x).end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define PB push_back // 挿入
#define MP make_pair // pairのコンストラクタ
// V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000; // 10の12乗
ll cnt = 0;
int n, m;
vector<vector<int>> v(200000);
vector<bool> seen(200000);
void dfs(int k) {
  if (!seen[k]) {
    seen[k] = true;
    for (auto next : v[k]) {
      if (seen[next])
        continue;
      dfs(next);
    }
    cnt++;
  }
}

int main() {

  cin >> n >> m;
  ll ans = 0;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  rep(i, n) {
    if (seen[i])
      continue;
    dfs(i);
    chmax(ans, cnt);
    cnt = 0;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n - 1; i >= (int)(k); i--)
#define all(x) (x).begin(), (x).end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define PB push_back // 挿入
#define MP make_pair // pairのコンストラクタ
// V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000; // 10の12乗
ll cnt = 0;
int n, m;
vector<vector<int>> v(200000);
vector<bool> seen(200000);
void dfs(VVi vec, int k) {
  seen[k] = true;
  for (auto next : v[k]) {
    if (seen[next])
      continue;
    dfs(vec, next);
  }
  cnt++;
}

int main() {

  cin >> n >> m;
  ll ans = 0;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  rep(i, n) {
    if (seen[i])
      continue;
    dfs(v, i);
    chmax(ans, cnt);
    cnt = 0;
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
struct UnionFind {
  vector<int> par, size;
  UnionFind(int N) : par(N), size(N) {
    for (int i = 0; i < N; i++)
      par[i] = i, size[i] = 1;
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
    size[ry] += size[rx];
  }
  bool same(int x, int y) {
    int rx = root(x), ry = root(y);
    return rx == ry;
  }
  int s(int x) { return size[x]; }
};
signed main() {
  int N, M, i, ans = 1;
  cin >> N >> M;
  UnionFind UF(N);
  REP(i, M) {
    int A, B;
    cin >> A >> B;
    UF.unite(A - 1, B - 1);
  }
  REP(i, N) ans = max(ans, UF.s(i));
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
signed main() {
  ll N, M, i, ans = 0;
  cin >> N >> M;
  vector<vector<ll>> X(N, vector<ll>());
  vector<P> Y;
  REP(i, M) {
    ll A, B;
    cin >> A >> B;
    Y.push_back(P(min(A, B), max(A, B)));
  }
  if (M == 0) {
    cout << 1 << endl;
    return 0;
  }
  sort(ALL(Y));
  X.at(Y.at(0).F - 1).push_back(Y.at(0).S - 1);
  X.at(Y.at(0).S - 1).push_back(Y.at(0).F - 1);
  FOR(i, 1, M) if (Y.at(i) != Y.at(i - 1)) {
    X.at(Y.at(i).F - 1).push_back(Y.at(i).S - 1);
    X.at(Y.at(i).S - 1).push_back(Y.at(i).F - 1);
  }
  vector<bool> A(N, 0);
  deque<ll> y;
  REP(i, N) if (!A.at(i)) {
    ll res = 0;
    y.push_back(i);
    A.at(i) = 1;
    while (y.size()) {
      ll x = y.front();
      y.pop_front();
      res++;
      REP(i, X.at(x).size()) if (!A.at(X.at(x).at(i))) {
        y.push_back(X.at(x).at(i));
        A.at(X.at(x).at(i)) = 1;
      }
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
  vector<int> par;

  UnionFind(int N) { par = vector<int>(N, -1); }

  int root(int x) {
    if (par.at(x) < 0)
      return x;
    return par.at(x) = root(par.at(x));
  }

  bool unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return false;
    if (par.at(rx) > par.at(ry))
      swap(rx, ry);
    par.at(rx) += par.at(ry);
    par.at(ry) = rx;
    return true;
  }

  int size(int x) { return -par.at(root(x)); }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind tree(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    tree.unite(A - 1, B - 1);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, tree.size(i));
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
  vector<int> par;

  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++)
      par.at(i) = -1;
  }

  int root(int x) {
    if (par.at(x) < x)
      return x;
    return par.at(x) = root(par.at(x));
  }

  bool unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return false;
    if (par.at(rx) > par.at(ry))
      swap(rx, ry);
    par.at(rx) += par.at(ry);
    par.at(ry) = rx;
    return true;
  }

  int size(int x) { return -par.at(root(x)); }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind tree(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    tree.unite(A - 1, B - 1);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, tree.size(i));
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T> void setmax(T &a, T const &b) {
  if (a < b)
    a = b;
}

template <class T> void setmin(T &a, T const &b) {
  if (a > b)
    a = b;
}

template <typename T, typename X> auto vectors(T a, X x) {
  return vector<T>(x, a);
}

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
  auto cont = vectors(a, y, zs...);
  return vector<decltype(cont)>(x, cont);
}

// 連結している頂点の集合について、それらは必ず別々に別れなければならない。

int main() {
  int N, M;
  cin >> N >> M;
  auto G = vectors(0, N, 0);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  vector<bool> visited(N, false);
  stack<int> stk;
  for (int i = 0; i < N; ++i) {
    stk.push(i);
  }
  auto dfs = [&](auto f, int cur, int &num) -> void {
    visited[cur] = true;
    ++num;
    for (int to : G[cur]) {
      if (!visited[to])
        f(f, to, num);
    }
  };
  int res = 0;
  while (!stk.empty()) {
    int vertex = stk.top();
    stk.pop();
    if (!visited[vertex]) {
      int tmp = 0;
      dfs(dfs, vertex, tmp);
      setmax(res, tmp);
    }
  }
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T> void setmax(T &a, T const &b) {
  if (a < b)
    a = b;
}

template <class T> void setmin(T &a, T const &b) {
  if (a > b)
    a = b;
}

template <typename T, typename X> auto vectors(T a, X x) {
  return vector<T>(x, a);
}

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
  auto cont = vectors(a, y, zs...);
  return vector<decltype(cont)>(x, cont);
}

// 連結している頂点の集合について、それらは必ず別々に別れなければならない。

int main() {
  int N, M;
  cin >> N >> M;
  auto G = vectors(0, N, 0);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  vector<bool> visited(N, false);
  stack<int> stk;
  for (int i = 0; i < N; ++i) {
    stk.push(i);
  }
  auto dfs = [&](auto f, int cur, int &num) -> int {
    visited[cur] = true;
    ++num;
    for (int to : G[cur]) {
      if (!visited[to])
        f(f, to, num);
    }
  };
  int res = 0;
  while (!stk.empty()) {
    int vertex = stk.top();
    stk.pop();
    if (!visited[vertex]) {
      int tmp = 0;
      dfs(dfs, vertex, tmp);
      setmax(res, tmp);
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const ll oo = 1e18 + 7;
const ll mod = 1e9 + 7, maxn = 2e5 + 10;
const long double PI = acos(-1);
int cnt = 1, ps[maxn], sz[maxn];

int find(int x) {
  if (x == ps[x])
    return x;
  return ps[x] = find(ps[x]);
}

void uni(int a, int b) {
  a = find(a);
  b = find(b);

  if (a == b)
    return;

  ps[a] = b;
  sz[b] += sz[a];
  cnt = max(cnt, sz[b]);
}

void init() {
  iota(ps, ps + maxn, 0);
  for (int i = 0; i < maxn; i++)
    sz[i] = 1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  init();

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    uni(--a, --b);
  }

  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define debug cout << "Ok" << endl;

using namespace std;

void solve() { return; }

vector<int> v(100100);
vector<int> ps(100100);
vector<int> qtd(100100, 1);

int find_set(int n) { return (ps[n] == n ? n : ps[n] = find_set(ps[n])); }
int ma = 0;

bool insert(int x, int y) {
  int xr = find_set(x);
  int yr = find_set(y);
  int l;

  if (xr == yr)
    return false;

  if (qtd[xr] < qtd[yr]) {
    l = xr;
    xr = yr;
    yr = l;
  }

  ps[yr] = xr;
  qtd[xr] += qtd[yr];
  ma = max(ma, qtd[xr]);
  return true;
}

int32_t main() {
  long long int n, m, a, b;

  cin >> n >> m;
  for (int i = 0; i <= n + 3; i++) {
    ps[i] = i;
  }
  while (m--) {
    cin >> a >> b;
    insert(a, b);
  }

  cout << ma << endl;
  return 0;
}