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

#include <iostream>
#include <stack>
#include <vector>
using namespace std;

static const int MAX = 200000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];
int rsl = 0;

void dfs(int r, int c) {
  int cnt = 0;
  stack<int> S;
  S.push(r);
  color[r] = c;
  cnt += 1;
  while (!S.empty()) {
    int u = S.top();
    S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
        color[v] = c;
        cnt += 1;
        S.push(v);
      }
    }
  }
  rsl = max(rsl, cnt);
}

void assignColor() {
  int id = 1;
  for (int i = 0; i < n; i++)
    color[i] = NIL;
  for (int u = 0; u < n; u++) {
    if (color[u] == NIL)
      dfs(u, id++);
  }
}

int main(void) {
  // Your code here!
  int s, t, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    s -= 1;
    t -= 1;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();
  cout << rsl << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
#include <vector>
using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];
int rsl = 0;

void dfs(int r, int c) {
  int cnt = 0;
  stack<int> S;
  S.push(r);
  color[r] = c;
  cnt += 1;
  while (!S.empty()) {
    int u = S.top();
    S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
        color[v] = c;
        cnt += 1;
        S.push(v);
      }
    }
  }
  rsl = max(rsl, cnt);
}

void assignColor() {
  int id = 1;
  for (int i = 0; i < n; i++)
    color[i] = NIL;
  for (int u = 0; u < n; u++) {
    if (color[u] == NIL)
      dfs(u, id++);
  }
}

int main(void) {
  // Your code here!
  int s, t, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    s -= 1;
    t -= 1;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();
  cout << rsl << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int parent[200005] = {};
int sz[200005] = {};
int n;

void init() {
  for (int i = 0; i < n; i++) {
    parent[i] = i;
    sz[i] = 1;
  }
}

int root(int u) {
  if (u == parent[u])
    return u;
  return root(parent[u]);
}

void join(int u, int v) {
  int ru = root(u);
  int rv = root(v);

  if (ru == rv)
    return;

  if (sz[rv] > sz[ru]) {
    parent[ru] = rv;
    sz[rv] += sz[ru];
  } else {
    parent[rv] = ru;
    sz[ru] += sz[rv];
  }
}

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

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    join(u, v);
  }

  vector<int> arr;

  for (int i = 0; i < n; i++) {
    if (parent[i] == i) {
      arr.push_back(sz[i]);
    }
  }

  sort(arr.begin(), arr.end());

  int group = 0;

  int del = 0;

  for (int i = 0; i < arr.size(); i++) {
    arr[i] -= del;
    group += arr[i];
    del += arr[i];
  }

  cout << group << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int parent[200005] = {};
int sz[200005] = {};

void init() {
  for (int i = 0; i < 200005; i++) {
    parent[i] = i;
    sz[i] = 1;
  }
}

int root(int u) {
  if (u == parent[u])
    return u;
  return root(parent[u]);
}

void join(int u, int v) {
  int ru = root(u);
  int rv = root(v);

  if (ru == rv)
    return;

  parent[ru] = rv;
  sz[rv] += sz[ru];
}

int main() {
  init();
  int n;
  cin >> n;
  int m;
  cin >> m;

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    join(u, v);
  }

  vector<int> arr;

  for (int i = 0; i < n; i++) {
    if (parent[i] == i) {
      arr.push_back(sz[i]);
    }
  }

  sort(arr.begin(), arr.end());

  int group = 0;

  int del = 0;

  for (int i = 0; i < arr.size(); i++) {
    arr[i] -= del;
    group += arr[i];
    del += arr[i];
  }

  cout << group << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

class UnionFind {
public:
  UnionFind(int n) : tree(vector<ll>(n, -1)) {}

  // 木の頂点を探す
  int find(int x) {
    if (tree[x] < 0)
      return x;
    return tree[x] = find(tree[x]);
  }

  // 長さを返す
  ll length(int x) {
    if (tree[x] < 0)
      return abs(tree[x]);
    return length(tree[x]);
  }

  // 同じグループか
  bool same(int x, int y) { return find(x) == find(y); }

  // 点xを含む木と点yを含む木の融合
  // 既に同じ木だったらfalseを返す
  bool unite(int x, int y) {
    int r1 = find(x);
    int r2 = find(y);
    if (r1 == r2)
      return false;
    // 大きい方に小さい方をくっつけたほうがコストが低い
    if (abs(r1) < abs(r2))
      swap(r1, r2);
    tree[r1] += tree[r2];
    tree[r2] = r1;
    return true;
  }

private:
  vector<ll> tree;
};

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

  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }

  ll ans = 0;
  vector<bool> visit(n + 1, false);
  for (int i = 0; i < n; i++) {
    int root = uf.find(i);
    if (visit[root])
      continue;
    visit[root] = true;
    ans = max(ans, uf.length(root));
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

class UnionFind {
public:
  UnionFind(int n) : tree(vector<ll>(n, -1)) {}

  // 木の頂点を探す
  int find(int x) {
    if (tree[x] < 0)
      return x;
    return tree[x] = find(tree[x]);
  }

  // 長さを返す
  ll length(int x) {
    if (tree[x] < 0)
      return abs(tree[x]);
    return length(tree[x]);
  }

  // 同じグループか
  bool same(int x, int y) { return find(x) == find(y); }

  // 点xを含む木と点yを含む木の融合
  // 既に同じ木だったらfalseを返す
  bool unite(int x, int y) {
    int r1 = find(x);
    int r2 = find(y);
    if (r1 == r2)
      return false;
    // 大きい方に小さい方をくっつけたほうがコストが低い
    if (abs(r1) < abs(r2))
      swap(r1, r2);
    tree[r1] += tree[r2];
    tree[r2] = r1;
    return true;
  }

private:
  vector<ll> tree;
};

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

  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, uf.length(i));
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define dbg(x) cout << "( " << #x << " -> " << x << " )" << endl;
using namespace std;
set<int> a[200005];
int vis[200005] = {0};
int cnt = 0, minIndex = 1;
void dfs(int node) {
  if (vis[node] == 1)
    return;
  vis[node] = 1;
  cnt++;
  for (int x : a[node])
    dfs(x);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u].insert(v);
    a[v].insert(u);
  }
  int prev = 0, maxi = INT_MIN;
  while (true) {
    dfs(minIndex);
    maxi = max(maxi, (cnt - prev));
    if (cnt == n)
      break;
    prev = cnt;
    for (int i = minIndex; i <= n; i++) {
      if (vis[i] == 0) {
        minIndex = i;
        break;
      }
    }
  }
  printf("%d\\n", maxi);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define dbg(x) cout << "( " << #x << " -> " << x << " )" << endl;
using namespace std;
set<int> a[200005];
int vis[200005] = {0};
int cnt = 0;
void dfs(int node) {
  if (vis[node] == 1)
    return;
  vis[node] = 1;
  cnt++;
  for (int x : a[node])
    dfs(x);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u].insert(v);
    a[v].insert(u);
  }
  int prev = 0, maxi = INT_MIN, index = 1;
  while (true) {
    dfs(index);
    maxi = max(maxi, (cnt - prev));
    if (cnt == n)
      break;
    prev = cnt;
    for (int i = 1; i <= n; i++) {
      if (vis[i] == 0) {
        index = i;
        break;
      }
    }
  }
  printf("%d\\n", maxi);
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll inf = 1e18;
vector<int> arr[2 * 100005];
bool vis[2 * 100005];
int val;
void dfs(int i) {
  if (vis[i])
    return;
  vis[i] = 1;
  val++;
  for (int c : arr[i])
    if (!vis[c])
      dfs(c);
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    val = 0;
    if (!vis[i])
      dfs(i);
    ans = max(val, ans);
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define forn(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vector<bool> t(100005, false);
// vvi adj(100005);

int dfs(int n, vvi &adj) {
  t[n] = true;
  int c = 1;
  for (int i = 0; i < (int)adj[n].size(); i++) {
    if (t[adj[n][i]] == false) {
      c += dfs(adj[n][i], adj);
    }
  }
  return c;
}

int32_t main() {
  fast

      int test = 1;
  // cin>>test;

  while (test--) {
    int n, m;
    cin >> n >> m;

    vvi adj(n + 1);

    forn(i, m) {
      int x, y;
      cin >> x >> y;
      adj[x].pb(y);
      adj[y].pb(x);
    }

    int ans = 1;

    for (int i = 1; i <= n; i++) {
      if (t[i] == false) {
        ans = max(ans, dfs(i, adj));
      }
    }

    cout << ans;

    // while ending
  }

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

#include <bits/stdc++.h>
#pragma GCC optimize(3)
#define endl '\\n'
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
} _io;
int parent[200005], value[200005];
int maxn = 1;

int find(int a) {
  if (parent[a] == a) {
    return a;
  } else {
    return find(parent[a]);
  }
}

void freedom(int n) {
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    value[i] = 1;
  }
  return;
}

void unionxy(int a, int b) {
  if (find(a) == find(b)) {
    return;
  } else {
    value[find(a)] += value[find(b)];
    maxn = max(maxn, value[find(a)]);
    parent[find(b)] = find(a);
    parent[b] = parent[find(b)];
    parent[a] = parent[find(a)];
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  freedom(n);
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    unionxy(a, b);
  }
  cout << maxn << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize(3)
#define endl '\\n'
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
} _io;
int parent[200005], value[200005];
int maxn = 1;

int find(int a) {
  if (parent[a] == a) {
    return a;
  } else {
    return find(parent[a]);
  }
}

void freedom(int n) {
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    value[i] = 1;
  }
  return;
}

void unionxy(int a, int b) {
  if (find(a) == find(b)) {
    return;
  } else {
    value[find(a)] += value[find(b)];
    maxn = max(maxn, value[find(a)]);
    parent[find(b)] = find(a);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  freedom(n);
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    unionxy(a, b);
  }
  cout << maxn << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct UnionFind {
  vector<int> par;
  vector<int> siz;

  UnionFind(int n) : par(n), siz(n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      siz[i] = 1;
    }
  }

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

  int size(int x) {
    if (par[x] == x)
      return siz[x];
    else
      return siz[x] = size(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx != ry) {
      par[ry] = rx;
      siz[rx] += siz[ry];
    }
  }

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

signed main() {
  // cout << fixed << setprecision(10) << flush;

  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 - 1, b - 1);
  }

  int maxsize = 0;
  for (int i = 0; i < n; i++) {
    maxsize = max(maxsize, uf.siz[i]);
  }
  cout << maxsize << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

struct UnionFind {
  vector<int> par;
  vector<int> siz;

  UnionFind(int n) : par(n), siz(n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      siz[i] = 1;
    }
  }

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

  int size(int x) {
    if (par[x] == x)
      return siz[x];
    else
      return siz[x] = size(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx != ry) {
      par[ry] = rx;
      siz[rx] += siz[ry];
    }
  }

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

signed main() {
  // cout << fixed << setprecision(10) << flush;

  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 - 1, b - 1);
  }

  int maxsize = 0;
  for (int i = 0; i < n; i++) {
    maxsize = max(maxsize, uf.size(i));
  }
  cout << maxsize << endl;

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

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

struct UnionFind {
  vector<int> par;
  vector<int> siz;

  UnionFind(int n) : par(n), siz(n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      siz[i] = 1;
    }
  }

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

  int size(int x) { return siz[root(x)]; }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx != ry) {
      par[ry] = rx;
      siz[rx] += siz[ry];
    }
  }

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

signed main() {
  // cout << fixed << setprecision(10) << flush;

  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 - 1, b - 1);
  }

  int maxsize = 0;
  for (int i = 0; i < n; i++) {
    maxsize = max(maxsize, uf.size(i));
  }
  cout << maxsize << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

struct UnionFind {
  vector<int> par;
  vector<int> siz;

  UnionFind(int n) : par(n), siz(n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      siz[i] = 1;
    }
  }

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

  int size(int x) {
    if (par[x] == x)
      return siz[x];
    else
      return siz[x] = size(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx != ry) {
      par[ry] = rx;
      siz[rx] += siz[ry];
    }
  }

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

signed main() {
  // cout << fixed << setprecision(10) << flush;

  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 - 1, b - 1);
  }

  int maxsize = 0;
  for (int i = 0; i < n; i++) {
    maxsize = max(maxsize, uf.size(i));
  }
  cout << maxsize << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n) { rep(i, n) par[i] = i; }
  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);
    int ry = root(y);
    if (rx == ry)
      return;
    par[rx] = ry;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind tree(n);
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    tree.unite(a, b);
  }
  vector<int> ans(n);
  rep(i, n) {
    ans[tree.root(i)]++;
    // cout<<tree.par[i]<<endl;
  }
  sort(ans.begin(), ans.end(), greater<int>());
  cout << ans[0] << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  vector<vector<int>> rel(n, vector<int>(n));
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    rel[a[i]].push_back(b[i]);
    rel[b[i]].push_back(a[i]);
  }
  rep(i, n) {
    std::sort(rel[i].begin(), rel[i].end());
    rel[i].erase(std::unique(rel[i].begin(), rel[i].end()), rel[i].end());
  }
  int ans = 0;

  rep(i, n) {
    int k = rel.at(i).size();
    ans = max(ans, n);
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct UnionFind {
  vector<int> r;
  UnionFind(int N) { r = vector<int>(N, -1); }
  int root(int x) {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  int size(int x) { return -r[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind UF(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    UF.unite(a, b);
  }
  int ans = 0;
  rep(i, n) ans = max(ans, UF.size(i));
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ab(n, 0);
  vector<vector<int>> ab_bool(n, vector<int>(n, 0));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (ab_bool[a][b] != 1) {
      ab[a]++;
      ab[b]++;
    }
    ab_bool[a][b] = 1;
    ab_bool[b][a] = 1;
  }
  int ans = 0;
  ans = max(ans, *max_element(ab.begin(), ab.end()));
  cout << ans + 1 << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

vector<int> par;

int find(int n) {
  if (par[n] < 0)
    return n;
  return par[n] = find(par[n]);
}

void uni(int a, int b) {
  par[a] += par[b];
  par[b] = a;
}

int main() {
  // freopen("input.in","r",stdin);
  // freopen("output.in","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j, k, n, m;
  cin >> n >> m;
  par = vector<int>(n + 1, -1);
  int x, y;
  while (m--) {
    cin >> x >> y;
    x = find(x);
    y = find(y);
    if (x != y)
      uni(x, y);
  }
  cout << -*min_element(par.begin(), par.end());

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main() {
  // freopen("input.in","r",stdin);
  // freopen("output.in","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j, t, n, m;
  cin >> n >> m;
  int arr[n + 1];
  // for(i=1;i<=n;i++)cin>>arr[i];
  vector<vector<int>> v;
  map<int, int> mp;
  int a, b;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    if (!mp[a] && !mp[b]) {
      v.push_back({a, b});
      mp[a] = v.size();
      mp[b] = mp[a];
    } else {
      if (mp[a] && !mp[b]) {
        v[mp[a] - 1].push_back(b);
        mp[b] = mp[a];
      } else if (mp[b] && !mp[a]) {
        v[mp[b] - 1].push_back(a);
        mp[a] = mp[b];
      } else if (mp[a] && mp[b] && mp[a] != mp[b]) {
        for (auto it : v[mp[b] - 1]) {
          v[mp[a] - 1].push_back({it});
          mp[it] = mp[a];
        }
        v.erase(v.begin() + mp[b] - 1);
      }
    }
  }
  int mi(0), temp;
  for (i = 0; i < v.size(); i++) {
    temp = v[i].size();
    mi = max(temp, mi);
  }
  cout << mi;
  /*int ans(0);
  for(i=0;i<v.size();i++){
          sort(v[i].begin(), v[i].end());
          ans+=arr[v[i][0]];
  }
  cout<<ans;*/

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

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

#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define pb push_back

int n, m;
vector<int> adj[200005];
bool vis[200005];
int ans = 1;
int cnt = 0;
void dfs(int n) {
  cnt++;
  vis[n] = 1;
  ans = max(ans, cnt);
  for (int x : adj[n]) {
    if (!vis[x]) {
      dfs(x);
    }
  }
}
int main() {

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].pb(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt = 0;
      dfs(i);
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

vector<int> adj[200005];
bool vis[200000];
int ans = 1, cnt;

void dfs(int n) {
  cnt++;
  vis[n] = 1;
  ans = max(ans, cnt);
  for (int x : adj[n]) {
    if (!vis[x]) {
      dfs(x);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt = 0;
      dfs(i);
    }
  }
  cout << ans << endl;
}