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

#include <bits/stdc++.h>

using namespace std;

const int MAX = 2 * 1000 * 100 + 11;
int parent[MAX];
int n, m;

void make_set(int node) { parent[node] = node; }

int find_set(int node) {
  if (node == parent[node]) {
    return node;
  }

  return parent[node] = find_set(parent[node]);
}

void union_sets(int firstNode, int secondNode) {
  int parentOfFirstNode = find_set(firstNode);
  int parentOfSecondNode = find_set(secondNode);

  if (parentOfFirstNode != parentOfSecondNode) {
    parent[parentOfSecondNode] = parentOfFirstNode;
  }
}

map<int, int> mp;

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

  for (int i = 0; i < n; i++) {
    make_set(i);
  }

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    union_sets(x, y);
  }

  for (int i = 1; i <= n; i++) {
    mp[find_set(i)]++;
  }

  int res = 0;
  for (auto it : mp) {
    res = max(res, it.second);
  }

  cout << res;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int MAX = 2 * 1000 * 100 + 11;
int parent[MAX];
int n, m;

void make_set(int node) { parent[node] = node; }

int find_set(int node) {
  if (node == parent[node]) {
    return node;
  }

  return find_set(parent[node]);
}

void union_sets(int firstNode, int secondNode) {
  int parentOfFirstNode = find_set(firstNode);
  int parentOfSecondNode = find_set(secondNode);

  if (parentOfFirstNode != parentOfSecondNode) {
    parent[parentOfSecondNode] = parentOfFirstNode;
  }
}

map<int, int> mp;

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

  for (int i = 0; i < n; i++) {
    make_set(i);
  }

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    union_sets(x, y);
  }

  for (int i = 1; i <= n; i++) {
    mp[find_set(i)]++;
  }

  int res = 0;
  for (auto it : mp) {
    res = max(res, it.second);
  }

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

#include <bits/stdc++.h>

using namespace std;

const int MAX = 2000 * 100 + 11;
vector<int> a[MAX];
vector<bool> vis(MAX);
int n, m;
int res = 0, curr = 0;

void dfs(int currNode) {
  if (vis[currNode]) {
    return;
  }

  curr++;
  vis[currNode] = true;
  for (auto it : a[currNode]) {
    dfs(it);
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }

  for (int i = 0; i < n; i++) {
    dfs(i);
    res = max(res, curr);
    curr = 0;
  }

  cout << res;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1000 * 100 + 11;
vector<int> a[MAX];
vector<bool> vis(MAX);
int n, m;
int res = 0, curr = 0;

void dfs(int currNode) {
  if (vis[currNode]) {
    return;
  }

  curr++;
  vis[currNode] = true;
  for (auto it : a[currNode]) {
    dfs(it);
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }

  for (int i = 0; i < n; i++) {
    dfs(i);
    res = max(res, curr);
    curr = 0;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ff(i, s, n) for (int i = s; i < n; i++)
#define fr(i, s, n) for (int i = n - 1; i >= s; i--)
#define llu long long int
const int mod = 1000000007;

int val = 0;
void dfs(set<int> adj[], bool visited[], int source) {
  val++;
  visited[source] = true;
  set<int>::iterator i;
  for (i = adj[source].begin(); i != adj[source].end(); ++i)
    if (!visited[*i])
      dfs(adj, visited, *i);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, e;
  cin >> n >> e;
  set<int> adj[n];
  for (int i = 0; i < e; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    // if(find(adj[a].begin(),adj[a].end(),b)==adj[a].end())
    adj[a].insert(b);
    // if(find(adj[b].begin(),adj[b].end(),a)==adj[b].end())
    adj[b].insert(a);
  }

  bool visited[n];
  memset(visited, false, sizeof(visited));

  int ans = 0;
  for (int i = 0; i < n; i++) {
    val = 0;
    // TODO: for every node do DFS
    if (!visited[i]) {
      dfs(adj, visited, i);
      ans = max(ans, val);
    }
  }
  cout << ans;
  return 0;
}

// 1
// 7 2
// 3 5 4 5 1 1 1


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ff(i, s, n) for (int i = s; i < n; i++)
#define fr(i, s, n) for (int i = n - 1; i >= s; i--)
#define llu long long int
const int mod = 1000000007;

int val = 0;
void dfs(vector<int> adj[], bool visited[], int source) {
  val++;
  visited[source] = true;
  vector<int>::iterator i;
  for (i = adj[source].begin(); i != adj[source].end(); ++i)
    if (!visited[*i])
      dfs(adj, visited, *i);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, e;
  cin >> n >> e;
  vector<int> adj[n];
  for (int i = 0; i < e; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (find(adj[a].begin(), adj[a].end(), b) == adj[a].end())
      adj[a].push_back(b);
    if (find(adj[b].begin(), adj[b].end(), a) == adj[b].end())
      adj[b].push_back(a);
  }

  bool visited[n];
  memset(visited, false, sizeof(visited));

  int ans = 0;
  for (int i = 0; i < n; i++) {
    val = 0;
    // TODO: for every node do DFS
    if (!visited[i]) {
      dfs(adj, visited, i);
      ans = max(ans, val);
    }
  }
  cout << ans;
  return 0;
}

// 1
// 7 2
// 3 5 4 5 1 1 1
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {

  long n, m;
  cin >> n >> m;
  UnionFind uf(n);
  int a, b;
  REP(i, m) {
    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: -6
free(): invalid pointer


Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

void connect(vector<long> &node, long a, long b) {
  long idx, target;
  if (node[a] == node[b]) {
    return;
  } else if (node[a] < node[b]) {
    target = node[b];
    idx = node[a];
    node[b] = idx;

  } else if (node[a] > node[b]) {
    target = node[a];
    idx = node[b];
    node[a] = idx;
  }
  auto itr = find(node.begin(), node.end(), target);
  while (itr != node.end()) {
    const long change_idx = distance(node.begin(), itr);
    node[change_idx] = idx;
    itr = find(node.begin(), node.end(), target);
  }
}

int main() {

  long n, m;
  cin >> n >> m;
  vector<long> node(n);
  vector<long> comp_size(n, 0);
  REP(i, n) { node[i] = i; }

  if (m == 0) {
    cout << 1 << endl;
    return 0;
  } else if (m == 1) {
    cout << 2 << endl;
    return 0;
  }
  long a, b;
  REP(i, m) {
    cin >> a >> b;
    connect(node, a, b);
  }
  REP(i, n) { comp_size[node[i]]++; }
  long max = *max_element(comp_size.begin(), comp_size.end());
  cout << max << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main(void) {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> edge(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    std::cin >> u >> v;
    --u;
    --v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  std::vector<bool> Yet(n, true);
  std::vector<int> Stack(n);
  int res = 0;
  for (int i = 0; i < n; ++i)
    if (Yet[i]) {
      int len = 0, cnt = 0;
      Stack[len++] = i;
      ++cnt;
      Yet[i] = false;
      while (len) {
        const int v = Stack[--len];
        for (const int nv : edge[v])
          if (Yet[nv]) {
            Stack[len++] = nv;
            ++cnt;
            Yet[nv] = false;
          }
      }
      if (res < cnt)
        res = cnt;
    }
  std::cout << res << '\\n';

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <vector>

int main(void) {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> edge(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    std::cin >> u >> v;
    --u;
    --v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  std::vector<bool> Yet(n, true);
  std::vector<int> Stack(n);
  int res = 0;
  for (int i = 0; i < n; ++i)
    if (Yet[i]) {
      int len = 0, cnt = 0;
      Stack[len++] = i;
      ++cnt;
      while (len) {
        const int v = Stack[--len];
        for (const int nv : edge[v])
          if (Yet[nv]) {
            Stack[len++] = nv;
            ++cnt;
          }
      }
      if (res < cnt)
        res = cnt;
    }
  std::cout << res << '\\n';

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

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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;

int pre[NMAX], a[NMAX];
inline int find(int x) { return pre[x] = (x == pre[x] ? x : find(pre[x])); }
int main(int argc, char const *argv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++)
    pre[i] = i;
  int u, v;
  while (m--) {
    scanf("%d%d", &u, &v);
    int u_pre = find(u), v_pre = find(v);
    if (u_pre == v_pre)
      continue;
    pre[u_pre] = v_pre;
  }
  int ans = 0;
  for (register int i = 1; i <= n; i++)
    a[find(i)] += 1, ans = max(ans, a[find(i)]);
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;

int pre[NMAX], a[NMAX];
inline int find(int x) { return x == pre[x] ? x : find(pre[x]); }
int main(int argc, char const *argv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++)
    pre[i] = i;
  int u, v;
  while (m--) {
    scanf("%d%d", &u, &v);
    int u_pre = find(u), v_pre = find(v);
    if (u_pre == v_pre)
      continue;
    pre[u_pre] = v_pre;
  }
  int ans = 0;
  for (register int i = 1; i <= n; i++)
    a[find(i)] += 1, ans = max(ans, a[find(i)]);
  printf("%d\\n", ans);
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
vi groups;
int find(int i) {
  int p = i;
  while (groups[i] > 0)
    i = groups[i];
  if (p != i)
    groups[p] = i;
  return i;
}
void join(int j, int k) {
  int g1 = find(j), g2 = find(k);
  if (g1 != g2) {
    if (-groups[g1] > -groups[g2]) {
      // groups[j]=g2;
      groups[g1] = -(-groups[g2] - groups[g1]);
      groups[g2] = g1;
      groups[k] = g1;
    } else {
      groups[g2] = -(-groups[g2] - groups[g1]);
      groups[g1] = g2;
      groups[j] = g2;
    }
  }
}
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, i, j, k;
  cin >> n >> m;
  groups.assign(n + 1, -1);
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    join(j, k);
  }
  // for(i=1;i<=n;i++)cout<<groups[i]<<" ";cout<<endl;
  vi g(n + 1, 0);
  int ans = 0;
  for (i = 1; i <= n; i++) {
    g[find(i)]++;
  }
  // cout<<find1(1);
  for (i = 1; i <= n; i++)
    ans = max(g[i], ans);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
vi groups;
int find(int i) {
  int p = i;
  while (groups[i] != -1)
    i = groups[i];
  if (p != i)
    groups[p] = i;
  return i;
}
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, i, j, k;
  cin >> n >> m;
  groups.assign(n + 1, -1);
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    int g1 = find(j), g2 = find(k);
    if (g1 != g2) {
      groups[j] = g2;
      groups[g1] = g2;
    }
  }
  // for(i=1;i<=n;i++)cout<<groups[i]<<" ";cout<<endl;
  vi g(n + 1, 0);
  int ans = 0;
  for (i = 1; i <= n; i++) {
    g[find(i)]++;
  }
  // cout<<find1(1);
  for (i = 1; i <= n; i++)
    ans = max(g[i], ans);
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll visited[200010];
ll nodes = 0;
vector<ll> A[200010];
int dfs(ll ind) {
  if (visited[ind])
    return 0;

  nodes++;
  visited[ind] = 1;
  for (auto i : A[ind]) {
    dfs(i);
  }
  return nodes;
}
int main() {

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // // freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(visited, 0, sizeof(visited));

  ll n, m, u, v;
  cin >> n >> m;

  for (ll i = 0; i < m; i++) {
    cin >> u >> v;
    A[v].push_back(u);
    A[u].push_back(v);
  }

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {

    if (visited[i] == 0) {
      nodes = 0;
      dfs(i);
      ans = max(ans, nodes);
    }
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll visited[100000];
ll nodes = 0;
vector<ll> A[100000];
int dfs(ll ind) {
  if (visited[ind])
    return 0;

  nodes++;
  visited[ind] = 1;
  for (auto i : A[ind]) {
    dfs(i);
  }
  return nodes;
}
int main() {

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // // freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(visited, 0, sizeof(visited));

  ll n, m, u, v;
  cin >> n >> m;

  for (ll i = 0; i < m; i++) {
    cin >> u >> v;
    A[v].push_back(u);
    A[u].push_back(v);
  }

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {

    if (visited[i] == 0) {
      nodes = 0;
      dfs(i);
      ans = max(ans, nodes);
    }
  }
  cout << ans;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

class UnionFind {
public:
  vector<ll> par;
  vector<ll> siz;

  UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i)
      par[i] = i;
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1);
    for (ll i = 0; i < sz_; ++i)
      par[i] = i;
  }

  ll root(ll x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (siz[x] < siz[y])
      swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) { return root(x) == root(y); }

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

int main() {
  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.merge(a, b);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int t = uf.size(i);
    if (ans < t) {
      ans = t;
    }
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

class UnionFind {
public:
  vector<ll> par;
  vector<ll> siz;

  UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i)
      par[i] = i;
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1);
    for (ll i = 0; i < sz_; ++i)
      par[i] = i;
  }

  ll root(ll x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (siz[x] < siz[y])
      swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) { return root(x) == root(y); }

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

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

  UnionFind uf(n);

  int flag[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      flag[i][j] = 0;
    }
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (flag[a - 1][b - 1] == 0) {
      flag[a - 1][b - 1] = 1;
      uf.merge(a - 1, b - 1);
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int t = uf.size(i);
    if (ans < t) {
      ans = t;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans = 1;
int par[200001] = {};
int r[200001] = {};
int si[200001] = {};

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

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (r[x] < r[y]) {
    par[x] = y; // 親をyにする
    si[y] += si[x];
    ans = max(ans, si[y]);
  } else {
    par[y] = x;
    si[x] += si[y];
    ans = max(ans, si[x]);
    if (r[x] == r[y])
      r[x]++;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n + 1; i++) {
    par[i] = i;
    si[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    unite(x, y);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans = 1;
int par[200001] = {};
int r[200001] = {};
int si[200001] = {};

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

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (r[x] < r[y]) {
    par[x] += y; // 親をyにする
    si[y] += si[x];
    ans = max(ans, si[y]);
  } else {
    par[y] = x;
    si[x] += si[y];
    ans = max(ans, si[x]);
    if (r[x] == r[y])
      r[x]++;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n + 1; i++) {
    par[i] = i;
    si[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    unite(x, y);
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int s[200005];
int cnt[200005];

int fa(int x) { return s[x] == x ? x : (s[x] = fa(s[x])); }

void merge(int a, int b) {
  int t1 = fa(a);
  int t2 = fa(b);
  if (t1 != t2)
    s[t1] = t2;
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    s[i] = i;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    merge(a, b);
  }

  int ans = 0;

  for (int i = 1; i <= n; i++)
    ans = max(ans, ++cnt[fa(i)]);

  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int s[20];
bool vis[20];
int fa(int x) { return s[x] < 0 ? x : (s[x] = fa(s[x])); }

void merge(int a, int b) {
  int t1 = fa(a);
  int t2 = fa(b);

  if (s[t2] < s[t1]) {
    s[t2] += s[t1];
    s[t1] = t2;
  } else {
    s[t1] += s[t2];
    s[t2] = t1;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    s[i] = -1;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (vis[a] && vis[b])
      continue;
    vis[a] = vis[b] = true;

    merge(a, b);
  }

  int ans = 0;

  for (int i = 1; i <= n; i++)
    if (s[i] < 0)
      ans = min(ans, s[i]);
  cout << -ans;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mod 1000000007
unordered_map<ll, vector<ll>> adj;
vector<ll> vis(300005, 0);
vector<ll> p(100005, 0);
ll c[100005];
ll cnt;
void dfs(ll node) {
  if (vis[node])
    return;
  vis[node] = 1;
  cnt++;
  for (auto i : adj[node]) {
    dfs(i);
  }
}
int main() {
  ll n, m;
  cin >> n >> m;
  ll a, b;
  map<pair<ll, ll>, ll> temp;
  while (m--) {
    cin >> a >> b;
    if (!temp[mp(a, b)]) {
      adj[a].pb(b);
      adj[b].pb(a);
      temp[mp(a, b)] = 1;
      temp[mp(b, a)] = 1;
    }
  }
  ll i;
  ll mx = 0;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    if (!vis[i]) {
      // cout<<i<<endl;
      dfs(i);
    }
    mx = max(cnt, mx);
  }
  cout << mx;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mod 1000000007
unordered_map<ll, vector<ll>> adj;
vector<ll> vis(100005, 0);
vector<ll> p(100005, 0);
ll c[100005];
ll cnt;
void dfs(ll node) {
  if (vis[node])
    return;
  vis[node] = 1;
  cnt++;
  for (auto i : adj[node]) {
    dfs(i);
  }
}
int main() {
  ll n, m;
  cin >> n >> m;
  ll a, b;
  if (m == 0) {
    cout << "1";
    return 0;
  }
  while (m--) {
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].pb(a);
  }
  ll i;
  ll mx = 0;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    if (!vis[i]) {
      // cout<<i<<endl;
      dfs(i);
    }
    mx = max(cnt, mx);
  }
  cout << mx;
}