alexjercan/bugnet huggingface dataset:
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
struct UnionFind {
  vector<int> r;
  UnionFind(int N) { r = vector<int>(N, -1); }
  int root(int x) {
    if (r[x] < 0)
      return x;
    r[x] = root(r[x]);
    return r[x];
  }
  bool unite(int a, int b) {
    int x = root(a);
    int y = root(b);
    if (x == y)
      return false;
    if (x > y)
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  int size(int x) { return -r[root(x)]; }
};
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  UnionFind UF(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    UF.unite(a, b);
  }
  int res = 1;
  for (int i = 0; i < n; i++) {
    res = max(res, UF.size(i));
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
struct UnionFind {
  vector<int> r;
  UnionFind(int N) { r = vector<int>(N, -1); }
  int root(int x) {
    if (r[x] < 0)
      return x;
    return root(r[x]);
  }
  bool unite(int a, int b) {
    int x = root(a);
    int y = root(b);
    if (x == y)
      return false;
    if (x > y)
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  int size(int x) { return -r[root(x)]; }
};
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  UnionFind UF(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    UF.unite(a, b);
  }
  int res = 1;
  for (int i = 0; i < n; i++) {
    res = max(res, UF.size(i));
  }
  cout << res << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define fr(n, x) for (ll n = 0; n < x; n++)
#define pf(x) cout << x << '\\n'
const ll mx = 3e5 + 4;
const ll mod = 1e9 + 7;
#pragma GCC optimize("O3")

vll graph[mx];
bool vis[mx] = {0};
ll res = 0;

void dfs(ll node) {
  vis[node] = 1;
  queue<ll> bfs;
  bfs.push(node);
  while (!bfs.empty()) {
    ll top = bfs.front();
    bfs.pop();
    res++;
    for (auto j : graph[top]) {
      if (!vis[j]) {
        bfs.push(j);
        vis[j] = 1;
      }
    }
  }
}

int main() {

  ll x, y;
  cin >> x >> y;
  set<pair<ll, ll>> edg;

  fr(n, y) {
    ll a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  ll mx = 0;
  for (ll n = 1; n <= x; n++) {
    if (!vis[n]) {
      res = 0;
      dfs(n);
      mx = max(mx, res);
      // cout << res << ' ' << n << '\\n';
    }
  }
  cout << mx;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define fr(n, x) for (ll n = 0; n < x; n++)
#define pf(x) cout << x << '\\n'
const ll mx = 1e5 + 4;
const ll mod = 1e9 + 7;
#pragma GCC optimize("O3")

vll graph[mx];
bool vis[mx] = {0};
ll res = 0;

void dfs(ll node) {
  vis[node] = 1;
  queue<ll> bfs;
  bfs.push(node);
  while (!bfs.empty()) {
    ll top = bfs.front();
    bfs.pop();
    res++;
    for (auto j : graph[top]) {
      if (!vis[j]) {
        bfs.push(j);
        vis[j] = 1;
      }
    }
  }
}

int main() {

  ll x, y;
  cin >> x >> y;
  set<pair<ll, ll>> edg;

  fr(n, y) {
    ll a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  ll mx = 0;
  for (ll n = 1; n <= x; n++) {
    if (!vis[n]) {
      res = 0;
      dfs(n);
      mx = max(mx, res);
      // cout << res << ' ' << n << '\\n';
    }
  }
  cout << mx;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

/*	[]__________[][][][]____[][][][][]__{}__[][][][]____[][][][][]__[][][][]
    []__________[]______________[]__________[]__________[]__________[]____[]
    []__________[][][][]________[]__________[][][][]____[]__________[]____[]
    []__________[]______________[]________________[]____[]__[][][]__[]____[]
    []__________[]______________[]________________[]____[]______[]__[]____[]
    [][][][]____[][][][]________[]__________[][][][]____[][][][][]__[][][][]
*/
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define endl '\\n'
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define decimal(x) cout << fixed << setprecision(x);
vector<int> adj[200005];
bool vis[200005];
int n;
vector<int> temp;
int c;
void dfs(int x) {
  vis[x] = true;
  c++;
  for (auto i : adj[x]) {
    if (!vis[i])
      dfs(i);
  }
}
void helper() {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      dfs(i);
      ans = max(ans, c);
      c = 0;
    }
  }
  cout << ans << endl;
}
void solve() {
  int m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  helper();
}
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}

Error: -11

Fixed submission:

/*	[]__________[][][][]____[][][][][]__{}__[][][][]____[][][][][]__[][][][]
    []__________[]______________[]__________[]__________[]__________[]____[]
    []__________[][][][]________[]__________[][][][]____[]__________[]____[]
    []__________[]______________[]________________[]____[]__[][][]__[]____[]
    []__________[]______________[]________________[]____[]______[]__[]____[]
    [][][][]____[][][][]________[]__________[][][][]____[][][][][]__[][][][]
*/
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define endl '\\n'
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define decimal(x) cout << fixed << setprecision(x);
vector<int> adj[100005];
bool vis[100005];
int n;
vector<int> temp;
int c;
void dfs(int x) {
  vis[x] = true;
  c++;
  for (auto i : adj[x]) {
    if (!vis[i])
      dfs(i);
  }
}
void helper() {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      dfs(i);
      ans = max(ans, c);
      c = 0;
    }
  }
  cout << ans << endl;
}
void solve() {
  int m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  helper();
}
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

const int max_n = 2e5 + 10;
int p[max_n];
int cnt[max_n];
int find(int x) {
  if (p[x] != x)
    p[x] = find(p[x]);
  return p[x];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    p[i] = i, cnt[i] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    int pa = find(a), pb = find(b);
    if (pa != pb) {
      p[pa] = pb;
      cnt[pb] += cnt[pa];
    }
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    res = max(res, cnt[i]);
  }
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

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

const int max_n = 200 + 10;
int p[max_n];
int cnt[max_n];
int find(int x) {
  if (p[x] != x)
    p[x] = find(p[x]);
  return p[x];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    p[i] = i, cnt[i] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (find(a) != find(b)) {
      if (a <= b) {
        p[b] = a, cnt[a]++;
      } else {
        p[a] = b, cnt[b]++;
      }
    }
  }
  int res = 0;
  for (int i = 1; i <= n; ++i)
    res = max(res, cnt[i]);
  cout << res << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
vector<int> adj[1000001];
bool visited[1000001];
int groupsize = 0;
int maxsize = 0;
void dfs(int s) {
  visited[s] = true;
  groupsize += 1;
  for (int i = 0; i < adj[s].size(); ++i) {
    if (visited[adj[s][i]] == false)
      dfs(adj[s][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    // cout << a << ' ' << b << '\\n';
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; ++i) {
    groupsize = 0;
    if (!visited[i]) {
      dfs(i);
      if (groupsize > maxsize) {
        maxsize = groupsize;
      }
    }
  }
  cout << maxsize;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
vector<int> adj[100001];
bool visited[100001];
int groupsize = 0;
int maxsize = 0;
void dfs(int s) {
  visited[s] = true;
  groupsize += 1;
  for (int i = 0; i < adj[s].size(); ++i) {
    if (visited[adj[s][i]] == false)
      dfs(adj[s][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    // cout << a << ' ' << b << '\\n';
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; ++i) {
    groupsize = 0;
    if (!visited[i]) {
      dfs(i);
      if (groupsize > maxsize) {
        maxsize = groupsize;
      }
    }
  }
  cout << maxsize;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORALL(i, n) for (int i = 0; i < n; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define endl "\\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n, m;
int a, b;
int par[200005];
int cnt[200005];

int findParent(int a) {
  if (par[a] == -1) {
    return a;
  }
  return par[a] = findParent(par[a]);
}

void merge(int a, int b) {
  int pa = findParent(a);
  int pb = findParent(b);

  if (pa != pb) {
    par[pa] = pb;
  }

  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> m;
  FOR(i, 0, n + 1) par[i] = -1;

  FORALL(i, m) {
    cin >> a >> b;
    merge(a, b);
  }

  FORALL(i, n + 1) { cnt[findParent(i)]++; }

  int maxi = 0;
  FOR(i, 1, n) { maxi = max(maxi, cnt[i]); }

  cout << maxi << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORALL(i, n) for (int i = 0; i < n; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define endl "\\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n, m;
int a, b;
int par[200005];
int cnt[200005];

int findParent(int a) {
  while (par[a] != -1) {
    a = par[a];
  }

  return a;
}

void merge(int a, int b) {
  int pa = findParent(a);
  int pb = findParent(b);

  if (pa != pb) {
    par[pa] = pb;
  }

  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> m;
  FOR(i, 0, n + 1) par[i] = -1;

  FORALL(i, m) {
    cin >> a >> b;
    merge(a, b);
  }

  FORALL(i, n + 1) { cnt[findParent(i)]++; }

  int maxi = 0;
  FOR(i, 1, n) { maxi = max(maxi, cnt[i]); }

  cout << maxi << endl;

  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  ;

  vector<vector<ll>> g(n + 1);
  for (long long i = 0; i < m; i++) {
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }

  ll maxl = 0;
  vector<ll> flag(n + 1, 0);
  vector<ll> c = a;
  c.insert(c.end(), b.begin(), b.end());

  for (auto y : c) {

    if (flag[y])
      continue;
    // BFS
    vector<ll> check(n + 1, -1);
    queue<ll> q;
    q.push(y);
    check[y] = 1;
    // flag[y]++;
    ll cun = 0;
    while (!q.empty()) {
      ll top = q.front();
      q.pop();
      cun++;
      maxl = max(maxl, cun);
      flag[top]++;
      for (auto x : g[top]) {
        if (check[x] < 0 and x != y) {

          q.push(x);
          check[x] = check[top] + 1;
        }
      }
    }
    // for(auto x : flag) cout << x << ' '; cout << endl;
  }
  // for(auto x : a) cout << x << " "; cout << endl;
  // for(auto x : b) cout << x << " "; cout << endl;

  if (m > 0)
    put(maxl);
  else
    put(1);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  ;

  vector<vector<ll>> g(n + 1);
  for (long long i = 0; i < m; i++) {
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }

  ll maxl = 0;
  vector<ll> flag(n + 1, 0);
  for (long long i = 1; i < n + 1; i++) {

    if (flag[i])
      continue;
    // BFS
    vector<ll> check(n + 1, -1);
    queue<ll> q;
    q.push(i);
    check[i] = 1;
    flag[i]++;
    ll cun = 0;
    while (!q.empty()) {
      ll top = q.front();
      q.pop();
      cun++;
      maxl = max(maxl, cun);

      for (auto x : g[top]) {
        if (check[x] < 0 and x != i) {
          flag[x]++;
          q.push(x);
          check[x] = check[top] + 1;
        }
      }
    }
    // for(auto x : flag) cout << x << ' '; cout << endl;
  }

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

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

int main(void) {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> G(N);
  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    p[i].first = min(a, b) - 1;
    p[i].second = max(a, b) - 1;
  }
  sort(p.begin(), p.end());

  int preva = 0, prevb = 0;
  for (int i = 0; i < M; i++) {
    if (preva == p[i].first && prevb == p[i].second)
      continue;

    preva = p[i].first;
    prevb = p[i].second;
    G[preva].push_back(prevb);
    G[prevb].push_back(preva);
  }

  /*
  for(int i=0;i<N;i++){
      for(int j=0;j<N;j++) if(rel[i][j]) cout << 'o'; else cout << 'x';
      cout << "\\n";
  }
  return 0;
  */

  vector<int> dist(N, -1);
  queue<int> q;
  int ans = 0;

  for (int v = 0; v < N; v++) {
    if (dist[v] != -1)
      continue;

    int tmp = 0;
    dist[v] = 0;
    q.push(v);

    while (!q.empty()) {
      int v = q.front();
      q.pop();
      tmp++;

      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue;
        dist[nv] = dist[v] + 1;
        q.push(nv);
      }
    }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  int N, M;
  cin >> N >> M;

  vector<vector<bool>> rel(N, vector<bool>(N, false));
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    rel[min(a, b)][max(a, b)] = true;
  }

  vector<vector<int>> G(N);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (rel[i][j]) {
        G[i].push_back(j);
        G[j].push_back(i);
      }
    }
  }

  /*
  for(int i=0;i<N;i++){
      for(int j=0;j<N;j++) if(rel[i][j]) cout << 'o'; else cout << 'x';
      cout << "\\n";
  }
  return 0;
  */

  vector<int> dist(N, -1);
  queue<int> q;
  int ans = 0;

  for (int v = 0; v < N; v++) {
    if (dist[v] != -1)
      continue;

    int tmp = 0;
    dist[v] = 0;
    q.push(v);

    while (!q.empty()) {
      int v = q.front();
      q.pop();
      tmp++;

      for (int nv : G[v]) {
        if (dist[nv] != -1)
          continue;
        dist[nv] = dist[v] + 1;
        q.push(nv);
      }
    }
    ans = max(ans, tmp);
  }

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll const MAX_N = 200005;

int par[MAX_N]; // 親
int r[MAX_N];   // 木の深さ
// n要素で初期化
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    r[i] = 0;
  }
}
// 木の根を求める
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
// xとyの属する集合を併合
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (r[x] < r[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}
// xとyが同じ集合に属するか否か
bool same(int x, int y) { return find(x) == find(y); }

int main() {
  ll N, M;
  cin >> N >> M;
  ll a, b;
  init(N);
  set<pair<ll, ll>> visited;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    a--, b--;
    if (visited.count({a, b}))
      continue;
    unite(a, b);
    visited.insert({a, b});
    visited.insert({b, a});
  }
  map<ll, ll> group_size;
  for (int i = 0; i < N; i++) {
    int root = find(i);
    group_size[root]++;
  }
  ll ans = 0;
  for (auto p : group_size) {
    ans = max(ans, p.second);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll const MAX_N = 100001;

int par[MAX_N]; // 親
int r[MAX_N];   // 木の深さ
// n要素で初期化
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    r[i] = 0;
  }
}
// 木の根を求める
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
// xとyの属する集合を併合
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (r[x] < r[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}
// xとyが同じ集合に属するか否か
bool same(int x, int y) { return find(x) == find(y); }

int main() {
  ll N, M;
  cin >> N >> M;
  ll a, b;
  init(N);
  set<pair<ll, ll>> visited;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (visited.count({a, b}))
      continue;
    unite(a, b);
    visited.insert({a, b});
    visited.insert({b, a});
  }
  map<ll, ll> group_size;
  for (int i = 1; i <= N; i++) {
    int root = find(i);
    group_size[root]++;
  }
  ll ans = 0;
  for (auto p : group_size) {
    ans = max(ans, p.second);
  }
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (i = k; i <= n; ++i)
#define REPR(i, k, n) for (int i = k; i >= n; --i)

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

int p[200000];
int cnt[200000];

int found(int x) {
  if (x == p[x]) {
    return x;
  }
  p[x] = found(p[x]);
  return p[x];
}

void solve() {
  memset(cnt, 0, sizeof(cnt));
  int N, M;
  cin >> N >> M;
  rep(i, N) { p[i] = i; }

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    int r1 = found(a);
    int r2 = found(b);
    p[r1] = r2;
  }

  rep(i, N) { cnt[found(i)]++; }

  int ans = 0;
  rep(i, N) { ans = max(cnt[i], ans); }

  cout << ans;
}

// #define LOCAL 1

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  solve();

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (i = k; i <= n; ++i)
#define REPR(i, k, n) for (int i = k; i >= n; --i)

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

int p[200001];

int found(int x) {
  if (x == p[x]) {
    return x;
  }
  return p[x] = found(p[x]);
}

void solve() {
  int N, M;
  cin >> N >> M;
  if (M == 0) {
    cout << 0;
  }
  rep(i, N + 1) { p[i] = i; }

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    int r1 = found(a);
    int r2 = found(b);
    p[r1] = r2;
  }

  int cnt[200001];
  rep(i, N + 1) {
    cnt[found(i)]++;
    //        cout << found(i) << " ";
  }
  //    cout << endl;

  int ans = 0;
  rep(i, N + 1) {
    //        cout << cnt[i] << " ";

    ans = max(cnt[i], ans);
  }
  //    cout << endl;
  cout << ans;
}

// #define LOCAL 1

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  // #ifdef LOCAL
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  string mode = "LOCAL";
  if (mode == getenv("MODE")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }

  solve();

  return 0;
}