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

#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
const int mod = 1e9 + 7;

struct Unionfind {
  vector<int> d;
  Unionfind(int n) : d(n, -1) {}
  int root(int x) {
    if (d[x] < 0) {
      return x;
    }
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(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 root(x) == root(y); }
  int size(int x) { return -d[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.unite(a, b);
  }
  int MAX = 0;
  for (int i = 0; i < N; i++) {
    chmax(MAX, uf.size(i));
  }
  cout << MAX << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
const int mod = 1e9 + 7;

struct Unionfind {
  vector<int> d;
  Unionfind(int n) : d(n, -1) {}
  int root(int x) {
    if (d[x] < 0) {
      return x;
    }
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return false;
    }
    if (d[x] > d[y]) {
      swap(x, y);
    }
    d[x] += d[y];
    d[y] = x;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[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.unite(a, b);
  }
  int MAX = 0;
  for (int i = 0; i < N; i++) {
    chmax(MAX, uf.size(i));
  }
  cout << MAX << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, xx, yy, x, y, ans;
int f[200001], siz[200001];

inline int get(int x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = get(f[x]);
}

int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    f[i] = i, siz[i] = 1;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    xx = get(x);
    yy = get(y);
    if (xx != yy) {
      f[xx] = yy;
      siz[yy] += siz[xx];
    }
    // for (j=1; j<=n; j++) printf("%d ",get(f[j])); puts("");
  }
  for (i = 1; i <= n; ++i)
    ans = max(ans, siz[i]);
  printf("%d\\n", ans);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, xx, yy, x, y;
int f[1001];

inline int get(int x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = get(f[x]);
}

int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    f[i] = i;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    xx = get(x);
    yy = get(y);
    f[xx] = yy;
    // for (j=1; j<=n; j++) printf("%d ",get(f[j])); puts("");
  }

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

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
vector<ll> Graph[200005];
ll cnt;
bool vis[200005];
void dfs(ll cur) {
  cnt++;
  vis[cur] = 1;
  for (auto h : Graph[cur]) {
    if (!vis[h]) {
      dfs(h);
    }
  }
}
int main() {
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  while (m--) {
    ll x, y;
    cin >> x >> y;
    Graph[x].push_back(y);
    Graph[y].push_back(x);
  }
  ll ans = 0;
  for (ll p = 1; p <= n; p++) {
    if (!vis[p]) {
      cnt = 0;
      dfs(p);
      ans = max(ans, cnt);
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
vector<ll> Graph[100002];
ll cnt;
bool vis[100002];
void dfs(ll cur) {
  cnt++;
  vis[cur] = 1;
  for (auto h : Graph[cur]) {
    if (!vis[h]) {
      dfs(h);
    }
  }
}
int main() {
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  while (m--) {
    ll x, y;
    cin >> x >> y;
    Graph[x].push_back(y);
    Graph[y].push_back(x);
  }
  ll ans = 0;
  for (ll p = 1; p <= n; p++) {
    if (!vis[p]) {
      cnt = 0;
      dfs(p);
      ans = max(ans, cnt);
    }
  }
  cout << ans;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error


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

const int MX = 400010;
vector<vector<int>> adj(MX + 1);

// adding edge utility
void add_edge(vector<vector<int>> &ref, int start, int end, bool dir) {

  ref[start].push_back(end);
  if (!dir) {
    ref[end].push_back(start);
  }
}

std::vector<bool> vis(MX + 1, false);
std::vector<ll> comp;

// DFS
void dfs(int v) {
  vis[v] = true;
  comp.push_back(v);
  for (auto u : adj[v]) {
    if (!vis[u]) {
      dfs(u);
    }
  }
  return;
}

// CONNECTED COMPONENTS
void find_comps(int n) {
  // std::vector<ll> arr;
  ll ans = INT_MIN;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      comp.clear();
      dfs(i);
      // for(auto u: comp) {
      //     cout << u << ' ';
      // }
      // cout << '\\n';
      // arr.push_back(comp.size());
      ans = max(ans, (ll)comp.size());
    }
  }
  cout << ans << '\\n';
  // for(auto it: arr) {
  //     cout << it << '\\n';
  // }
}

// testing
int32_t main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
  // for debug in error.txt
  freopen("error.txt", "w", stderr);
#endif
  int t = 1;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    while (m--) {
      int s, d;
      cin >> s >> d;
      s--, d--;
      add_edge(adj, s, d, 0);
    }
    find_comps(n);
  }
}

Error: -11

Fixed submission:


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

const int MX = 100010;
vector<vector<int>> adj(MX + 1);

// adding edge utility
void add_edge(vector<vector<int>> &ref, int start, int end, bool dir) {

  ref[start].push_back(end);
  if (!dir) {
    ref[end].push_back(start);
  }
}

std::vector<bool> vis(MX + 1, false);
std::vector<ll> comp;

// DFS
void dfs(int v) {
  vis[v] = true;
  comp.push_back(v);
  for (auto u : adj[v]) {
    if (!vis[u]) {
      dfs(u);
    }
  }
  return;
}

// CONNECTED COMPONENTS
void find_comps(int n) {
  // std::vector<ll> arr;
  ll ans = INT_MIN;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      comp.clear();
      dfs(i);
      // for(auto u: comp) {
      //     cout << u << ' ';
      // }
      // cout << '\\n';
      // arr.push_back(comp.size());
      ans = max(ans, (ll)comp.size());
    }
  }
  cout << ans << '\\n';
  // for(auto it: arr) {
  //     cout << it << '\\n';
  // }
}

// testing
int32_t main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
  // for debug in error.txt
  freopen("error.txt", "w", stderr);
#endif
  int t = 1;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    while (m--) {
      int s, d;
      cin >> s >> d;
      s--, d--;
      add_edge(adj, s, d, 0);
    }
    find_comps(n);
  }
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
;
int height[MAXN], s[MAXN];
int n, m;
void setInit() {
  for (int i = 1; i <= n; i++) {
    s[i] = i;
    height[i] = 0;
  }
}
int setFind(int x) {
  if (x != s[x])
    s[x] = setFind(s[x]);
  return s[x];
}
void setUnion(int x, int y) {
  x = setFind(x);
  y = setFind(y);
  if (height[x] == height[y]) {
    height[x]++;
    s[y] = x;
  } else {
    if (height[x] < height[y])
      s[x] = y;
    else
      s[y] = s[x];
  }
}
int main(int argc, char *argv[]) {
  scanf("%d %d", &n, &m);
  setInit();
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    setUnion(x, y);
  }
  int cnt[MAXN];
  for (int i = 1; i <= n; i++)
    cnt[i] = setFind(s[i]);
  int ans = -INF;
  sort(cnt + 1, cnt + n + 1);
  int num = 1;
  for (int i = 2; i <= n; i++) {
    if (cnt[i] == cnt[i - 1])
      num++;
    else
      ans = max(ans, num), num = 1;
  }
  cout << max(ans, num);
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
const int MAXN = 2e5 + 5;
int height[MAXN], s[MAXN], vis[MAXN];
int n, m;
void setInit() {
  for (int i = 1; i <= n; i++) {
    s[i] = i;
    height[i] = 0;
  }
}
int setFind(int x) {
  if (x != s[x])
    s[x] = setFind(s[x]);
  return s[x];
}
void setUnion(int x, int y) {
  x = setFind(x);
  y = setFind(y);
  if (height[x] == height[y]) {
    height[x]++;
    s[y] = x;
  } else {
    if (height[x] < height[y])
      s[x] = y;
    else
      s[y] = s[x];
  }
}
int main(int argc, char *argv[]) {
  scanf("%d %d", &n, &m);
  setInit();
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    vis[x] = vis[y] = 1;
    setUnion(x, y);
  }
  int ans = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      cnt++;
    if (s[i] == i && vis[i])
      ans++; // 集合数
  }
  printf("%d", cnt % ans == 0 ? cnt / ans : cnt / ans + 1);
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
vector<set<int>> matrix(200006);
vector<bool> visited(200006);
vector<set<int>> answer;
set<int> st;
void dfs(int v) {
  visited[v] = true;
  st.insert(v);
  // for(int i = 1; i <= matrix[v].size(); i++) {
  for (auto it = matrix[v].begin(); it != matrix[v].end(); it++) {
    if (visited[*it] == false) {
      st.insert(*it);
      dfs(*it);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  matrix = vector<set<int>>(n + 1);
  visited = vector<bool>(n + 1);
  map<int, bool> check;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    matrix[x].insert(y);
    matrix[y].insert(x);
    check[x] = true;
    check[y] = true;
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == false && check[i]) {
      dfs(i);
      ans = max(ans, (int)st.size());
      st.clear();
    }
  }
  cout << ans;
  // cout << answer.size() << endl;
  // for(int i = 0; i < answer.size(); i++) {
  //     cout << answer[i].size() << " ";
  //     for(auto it = answer[i].begin(); it != answer[i].end(); it++) {
  //         cout << *it << " ";
  //     }
  //     cout << endl;
  // }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> matrix;
vector<bool> visited;
vector<set<int>> answer;
set<int> st;
void dfs(int v) {
  visited[v] = true;
  st.insert(v);
  for (int i = 1; i <= matrix[v].size(); i++) {
    if (visited[i] == false && matrix[v][i] == 1) {
      st.insert(i);
      dfs(i);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  matrix = vector<vector<int>>(n + 1, vector<int>(n + 1));
  visited = vector<bool>(n + 1);
  map<int, bool> check;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    matrix[x][y] = 1;
    matrix[y][x] = 1;
    check[x] = true;
    check[y] = true;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == false && check[i]) {
      dfs(i);
      ans = max(ans, (int)st.size());
      st.clear();
    }
  }
  cout << ans;
  // cout << answer.size() << endl;
  // for(int i = 0; i < answer.size(); i++) {
  //     cout << answer[i].size() << " ";
  //     for(auto it = answer[i].begin(); it != answer[i].end(); it++) {
  //         cout << *it << " ";
  //     }
  //     cout << endl;
  // }
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int main() {
  int N, M;
  std::cin >> N >> M;

  std::vector<int> F(N, -1);

  auto get_parent = [&F](int idx) {
    int parent = idx;
    while (F[parent] != -1) {
      parent = F[parent];
    }
    int i = idx;
    while (F[i] != -1) {
      F[i] = parent;
      i = F[i];
    }
    return parent;
  };

  std::vector<int> count(N, 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    int pa = get_parent(a);
    int pb = get_parent(b);
    if (pa != pb) {
      F[pb] = pa;
      F[b] = pa;
      count[pa] += count[pb];
      count[pb] = 0;
    }
  }

  int max = count[0];
  for (int i = 0; i < N; i++) {
    max = std::max(max, count[i]);
  }
  std::cout << max << std::endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  int N, M;
  std::cin >> N >> M;

  std::vector<int> F(N, -1);

  auto get_parent = [&F](int idx) {
    int parent = idx;
    while (F[parent] != -1) {
      parent = F[parent];
    }
    return parent;
  };

  std::vector<int> count(N, 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    int pa = get_parent(a);
    int pb = get_parent(b);
    if (pa != pb) {
      F[pb] = pa;
      count[pa] += count[pb];
      count[pb] = 0;
    }
  }

  int max = count[0];
  for (int i = 0; i < N; i++) {
    max = std::max(max, count[i]);
  }
  std::cout << max << std::endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> G(n);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans = 0;
  queue<ll> que;
  vector<ll> dis(n, -1);
  for (ll i = 0; i < n; i++) {
    que.push(i);
    ll sum = 0;
    while (!que.empty()) {
      ll v = que.front();
      que.pop();
      for (ll nv : G[v]) {
        if (dis.at(nv) != -1) {
          continue;
        }
        dis.at(nv) = dis.at(v) + 1;
        que.push(nv);
        sum++;
      }
    }
    ans = max(ans, sum);
  }
  if (ans == 0) {
    ans = 1;
  }

  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> G(n);
  queue<ll> que;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans = 0;
  vector<ll> dis(n, -1);
  dis.at(0) = 0;
  ll sum = 1;
  for (ll i = 0; i < n; i++) {
    ll v = que.front();
    que.pop();
    for (ll nv : G[v]) {
      if (dis.at(nv) != -1) {
        continue;
      }
      dis.at(nv) = dis.at(v) + 1;
      que.push(nv);
      sum++;
    }
    ans++;
  }
  cout << sum;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> friends(n, 1);
  vector<ll> samewith(n);
  for (ll i = 0; i < n; i++) {
    samewith[i] = i;
  }
  for (ll i = 0; i < m; i++) {
    ll _a, _b;
    cin >> _a >> _b;
    ll a = _a - 1;
    ll b = _b - 1;
    ll ga = a;
    while (true) {
      if (samewith[ga] == ga)
        break;
      else
        ga = samewith[ga];
    }
    ll gb = b;
    while (true) {
      if (samewith[gb] == gb)
        break;
      else
        gb = samewith[gb];
    }
    if (ga == gb)
      continue;
    ll sum = friends[ga] + friends[gb];
    ll gab = min(ga, gb);
    friends[gab] = sum;
    samewith[a] = gab;
    samewith[b] = gab;
    samewith[ga] = gab;
    samewith[gb] = gab;
  }
  ll maxfriend = 0;
  for (ll i = 0; i < n; i++) {
    maxfriend = max(friends[i], maxfriend);
  }
  cout << maxfriend;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
/*
int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,ll>> relation(m);
    vector<ll> friends(n,1);
    for(ll i=0;i<m;i++){
      ll a,b;
      cin >> a >> b;
      relation[i] = pair<ll,ll>(a,b);
    }
}*/

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> friends(n, 0);
  vector<ll> samewith(n);
  for (ll i = 0; i < n; i++) {
    samewith[i] = i;
  }
  for (ll i = 0; i < m; i++) {
    ll _a, _b;
    cin >> _a >> _b;
    ll a = _a - 1;
    ll b = _b - 1;
    ll ga = samewith[a];
    ll gb = samewith[b];
    if (ga == gb)
      continue;
    ll gab = min(ga, gb);
    for (ll i = 0; i < n; i++) {
      if (samewith[i] == ga || samewith[i] == gb)
        samewith[i] = gab;
    }
  }
  for (ll i = 0; i < n; i++) {
    friends[samewith[i]]++;
  }
  ll maxfriend = 0;
  for (ll i = 0; i < n; i++) {
    maxfriend = max(friends[i], maxfriend);
  }
  cout << maxfriend;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const ll L = 2e5 + 5;
ll arr[L];
ll szz[L];
ll root(ll i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
void union1(ll i, ll j) {
  ll ri = root(i);
  ll rj = root(j);
  if (ri == rj)
    return;
  if (szz[ri] <= szz[rj]) {
    arr[ri] = rj;
    szz[rj] += szz[ri];
  } else {
    arr[rj] = ri;
    szz[ri] += szz[rj];
  }
}
ll find(ll i, ll j) {
  if (root(i) == root(j))
    return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n >> m;
  for (ll i = 1; i <= n; i++) {
    arr[i] = i;
    szz[i] = 1;
  }
  ll a, b;
  while (m--) {
    cin >> a >> b;
    union1(a, b);
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans = max(ans, szz[i]);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const ll L = 1e5 + 5;
ll arr[L];
ll szz[L];
ll root(ll i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
void union1(ll i, ll j) {
  ll ri = root(i);
  ll rj = root(j);
  if (ri == rj)
    return;
  if (szz[ri] <= szz[rj]) {
    arr[ri] = rj;
    szz[rj] += szz[ri];
  } else {
    arr[rj] = ri;
    szz[ri] += szz[rj];
  }
}
ll find(ll i, ll j) {
  if (root(i) == root(j))
    return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n >> m;
  for (ll i = 1; i <= n; i++) {
    arr[i] = i;
    szz[i] = 1;
  }
  ll a, b;
  while (m--) {
    cin >> a >> b;
    union1(a, b);
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans = max(ans, szz[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long
//  int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
vector<vector<lli>> adj;
vector<lli> vis;
lli n;
lli c = 0;
lli ans;
int dfs(int cur) {
  for (int j = 0; j < adj[cur].size(); j++) {
    int k = adj[cur][j];
    if (vis[k] == 0) {
      c += 1;
      vis[k] = 1;
      dfs(k);
    }
  }

  return 0;
}
void call_dfs() {
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      c = 1;
      vis[i] = 1;
      dfs(i);
      ans = max(c, ans);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli m;
  cin >> n >> m;
  ans = 1;
  vis.resize(n + 1, 0);
  adj.resize(n + 1);
  set<pll> edge;
  for1(i, 0, m) {
    lli a, b;
    cin >> a >> b;
    if (b < a) {
      swap(a, b);
    }
    edge.insert(mp(a, b));
  }
  for (auto itr = edge.begin(); itr != edge.end(); itr++) {
    pll p = *itr;
    adj[p.first].pb(p.second);
    adj[p.second].pb(p.first);
  }
  call_dfs();
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long
//  int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
vector<vector<lli>> adj;
vector<lli> vis;
lli n;
lli c = 0;
lli ans;
int dfs(int cur) {
  int p = cur;
  for (int j = 0; j < adj[cur].size(); j++) {
    int k = adj[cur][j];
    if (vis[k] == 0) {
      c += 1;
      vis[k] = 1;
      dfs(k);
    }
  }

  return 0;
}
int call_dfs() {
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      c = 1;
      vis[i] = 1;
      dfs(i);
      ans = max(c, ans);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli m;
  cin >> n >> m;
  ans = 1;
  vis.resize(n + 1, 0);
  adj.resize(n + 1);
  set<pll> edge;
  for1(i, 0, m) {
    lli a, b;
    cin >> a >> b;
    if (b < a) {
      swap(a, b);
    }
    edge.insert(mp(a, b));
  }
  for (auto itr = edge.begin(); itr != edge.end(); itr++) {
    pll p = *itr;
    adj[p.first].pb(p.second);
    adj[p.second].pb(p.first);
  }
  call_dfs();
  cout << ans << endl;
}