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

#include <bits/stdc++.h>
#include <cstdlib>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 100005LL
using namespace std;

vector<vector<ll>> graph(200005);
ll visited[200005];
ll x;
v ans;

void dfs(ll node) {

  visited[node] = 1;
  ans.pb(node);

  for (ll u : graph[node]) {
    if (!visited[u])
      dfs(u);
  }
}

auto solve() {
  ll n, m;
  cin >> n >> m;
  f(i, m) {
    ll a, b;
    cin >> a >> b;
    graph[a].pb(b);
    graph[b].pb(a);
  }
  v xxx;
  loop(i, 1, n + 1) {

    if (!visited[i]) {
      ans.clear();

      dfs(i);
      xxx.pb(ans.size());
    }
  }
  cout << *max_element(all(xxx)) << "\\n";
}

int main() {
  ll t = 1;
  while (t--)

    solve();
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <cstdlib>
#include <numeric>
#define ll long long int
#define all(x) x.begin(), x.end()

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

#define v vector<long long int>
#define vv vector<int>
#define gcd(m, n) __gcd(m, n)
#define vp vector<pair<long long int, long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int, long long int>
#define f(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, n) for (ll i = a; i < n; i += 1)
#define fe(d, e) for (auto d : e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll, ll>
#define N 100005LL
using namespace std;

vector<vector<ll>> graph(200005);
ll visited[200005];
ll x;
v ans;

ll dfs(ll node) {

  visited[node] = 1;
  ans.pb(node);

  for (ll u : graph[node]) {
    if (!visited[u])
      dfs(u);
  }
}

auto solve() {
  ll n, m;
  cin >> n >> m;
  f(i, m) {
    ll a, b;
    cin >> a >> b;
    graph[a].pb(b);
    graph[b].pb(a);
  }
  v xxx;
  loop(i, 1, n + 1) {

    if (!visited[i]) {
      ans.clear();

      dfs(i);
      xxx.pb(ans.size());
    }
  }
  cout << *max_element(all(xxx));
}

int main() {
  ll t = 1;
  while (t--)

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

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
vector<int> adj[MAXN];
bool visited[MAXN];
int n, m, mx = 0, curr = 0;

void dfs(int node) {
  visited[node] = true;
  for (int next : adj[node]) {
    if (!visited[next]) {
      curr++;
      dfs(next);
    }
  }
}

int main() {
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      curr = 1;
      dfs(i);
      mx = max(mx, curr);
    }
  }
  cout << mx << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
vector<int> adj[MAXN];
bool visited[MAXN];
int n, m, mx = 0, curr = 0;

void dfs(int node) {
  visited[node] = true;
  for (int next : adj[node]) {
    if (!visited[next]) {
      curr++;
      dfs(next);
    }
  }
}

int main() {
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      curr = 1;
      dfs(i);
      mx = max(mx, curr);
    }
  }
  cout << mx << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int maxn = 2e5 + 10;
vector<int> adj[maxn];
vector<bool> visited(maxn);
int cnt, res = 0;
void dfs(int node) {
  ++cnt;
  visited[node] = true;
  for (int u : adj[node]) {
    if (!visited[u])
      dfs(u);
  }
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    cnt = 0;
    if (!visited[i])
      dfs(i);
    res = max(res, cnt);
  }
  cout << res;
}

Error: TLE

Fixed submission:

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

const int maxn = 2e5 + 10;
vector<int> adj[maxn];
vector<bool> visited(maxn);
int cnt, res = 0;
void dfs(int node) {
  ++cnt;
  visited[node] = true;
  for (int u : adj[node]) {
    if (!visited[u])
      dfs(u);
  }
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    cnt = 0;
    dfs(i);
    res = max(res, cnt);
    visited.assign(n + 1, false);
  }
  cout << res;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

const int MAXN = 2e5 + 7;

int N, M;
vector<int> graph[MAXN];
bool visited[MAXN];

int DFS(int cur) {
  int ret = 1;
  visited[cur] = true;
  for (auto adj : graph[cur]) {
    if (visited[adj])
      continue;
    ret += DFS(adj);
  }

  return ret;
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (visited[i])
      continue;
    ans = max(ans, DFS(i));
  }

  printf("%d\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

const int MAXN = 1e5 + 7;

int N, M;
vector<int> graph[MAXN];
bool visited[MAXN];

int DFS(int cur) {
  int ret = 1;
  visited[cur] = true;
  for (auto adj : graph[cur]) {
    if (visited[adj])
      continue;
    ret += DFS(adj);
  }

  return ret;
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (visited[i])
      continue;
    ans = max(ans, DFS(i));
  }

  printf("%d\\n", ans);

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

// control+option+n to run!
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define NEGFOR(i, a, b) for (ll i = (a); i > (b); i--)
#define vll vector<long long>
#define sll set<long long>
#define ld long double
#define inf 1000000000000000000;
#define mll multiset<long long>
#define nn << "\\n"
#define F(i, b) for (ll i = 0; i < b; i++)
// 10^8 operations per second
// greatest int is 2,147,483,647
// greates long long is 9.22337204e18
// ALL FUNCTIONS SHOULD BE LL!!!!
int n, m;
ll co = 0;
vector<int> v[500002];
bool visited[500002];
void dfs(int node) {
  co++;
  visited[node] = true;
  for (int i = 0; i < v[node].size(); ++i) {
    int nxt = v[node][i];
    if (visited[nxt] == false)
      dfs(nxt);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> m;

  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vll vec;
  for (int i = 0; i < n; ++i) {
    if (visited[i] == false) {
      dfs(i);
      vec.pb(co);
      co = 0;
    }
  }
  ll x = vec.size();
  sort(vec.begin(), vec.end());
  ll currdelete = 0;
  ll ans = 0;
  FOR(i, 0, vec.size()) {
    ans += vec[i] - currdelete;
    currdelete = vec[i];
  }
  cout << ans;

  cout << "\\n"; // GET RID OF THIS FOR THE ACTUAL PROGRAM!!!!
}


Error: 0

Fixed submission:

// control+option+n to run!
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define NEGFOR(i, a, b) for (ll i = (a); i > (b); i--)
#define vll vector<long long>
#define sll set<long long>
#define ld long double
#define inf 1000000000000000000;
#define mll multiset<long long>
#define nn << "\\n"
#define F(i, b) for (ll i = 0; i < b; i++)
// 10^8 operations per second
// greatest int is 2,147,483,647
// greates long long is 9.22337204e18
// ALL FUNCTIONS SHOULD BE LL!!!!
int n, m;
ll co = 0;
vector<int> v[100002];
bool visited[100002];
void dfs(int node) {
  co++;
  visited[node] = true;
  for (int i = 0; i < v[node].size(); ++i) {
    int nxt = v[node][i];
    if (visited[nxt] == false)
      dfs(nxt);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> m;

  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vll vec;
  for (int i = 0; i < n; ++i) {
    if (visited[i] == false) {
      dfs(i);
      vec.pb(co);
      co = 0;
    }
  }
  ll x = vec.size();
  sort(vec.begin(), vec.end());
  ll currdelete = 0;
  ll ans = 0;
  FOR(i, 0, vec.size()) {
    ans += vec[i] - currdelete;
    currdelete = vec[i];
  }
  cout << ans;

  cout << "\\n"; // GET RID OF THIS FOR THE ACTUAL PROGRAM!!!!
}
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 X first
#define Y second
#define nl '\\n'
#define AC return 0
#define pb(a) push_back(a)
#define mst(a, b) memset(a, b, sizeof a)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define rep1(i, n) for (int i = 1; (i) <= (n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a, b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
// #pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f;
ll cnt[N], pre[N];

int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }

int main() {
  IOS;
  ll n, m, ans = MIN;
  cin >> n >> m;
  rep1(i, n) pre[i] = i;
  while (m--) {
    int a, b;
    cin >> a >> b;
    int x = find(a), y = find(b);
    if (x != y)
      pre[x] = y;
  }
  rep1(i, n) {
    int x = find(i);
    cnt[x]++, ans = max(ans, cnt[x]);
  }
  cout << ans << nl;

  AC;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define nl '\\n'
#define AC return 0
#define pb(a) push_back(a)
#define mst(a, b) memset(a, b, sizeof a)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define rep1(i, n) for (int i = 1; (i) <= (n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a, b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
// #pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f;
ll cnt[N], pre[N];

int find(int x) { return x == pre[x] ? x : find(pre[x]); }

int main() {
  IOS;
  ll n, m, ans = MIN;
  cin >> n >> m;
  rep1(i, n) pre[i] = i;
  while (m--) {
    int a, b;
    cin >> a >> b;
    int x = find(a), y = find(b);
    if (x != y)
      pre[x] = y;
  }
  rep1(i, n) {
    int x = find(i);
    cnt[x]++, ans = max(ans, cnt[x]);
  }
  cout << ans << nl;

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

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> d(n);
  vector<int> list(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    d[a].push_back(b);
    d[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (list[i] == 1)
      continue;
    queue<int> q;
    q.push(i);
    list[i] = 1;
    int sum = 1;
    while (!q.empty()) {
      int p = q.front();
      q.pop();
      for (auto np : d[p]) {
        if (list[np] == 1)
          continue;
        list[np] = 1;
        q.push(np);
        sum += 1;
      }
    }
    ans = max(ans, sum);
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> d(n);
  vector<int> list(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    d[a].push_back(b);
    d[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (list[i] == 1)
      continue;
    queue<int> q;
    q.push(i);
    list[i] = 1;
    int sum = 1;
    while (!q.empty()) {
      int p = q.front();
      q.pop();
      for (auto np : d[p]) {
        list[np] = 1;
        q.push(np);
        sum += 1;
      }
    }
    ans = max(ans, sum);
  }
  cout << ans;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<set<int>> popu(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    popu[a].insert(b);
    popu[b].insert(a);
  }

  vector<int> dist(n);
  int Max = 0;
  for (int i = 0; i < n; i++) {
    if (dist[i] != 0)
      continue;

    queue<int> que;
    dist[i] = 1;
    que.push(i);
    int sum = 1;

    while (!que.empty()) {
      int p = que.front();
      que.pop();

      for (auto np : popu[p]) {
        if (dist[np] != 0)
          continue;
        dist[np] = 1;
        sum += 1;
        que.push(np);
      }
    }
    Max = max(sum, Max);
  }
  cout << Max;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<set<int>> popu(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    popu[a].insert(b);
    popu[b].insert(a);
  }

  vector<int> list(n, 0);
  int Max = 0;
  for (int i = 0; i < n; i++) {
    if (list[i] != 0)
      continue;
    vector<int> dist(n);
    queue<int> que;

    dist[i] = 1;
    que.push(i);
    int sum = 1;

    while (!que.empty()) {
      int p = que.front();
      que.pop();

      for (auto np : popu[p]) {
        if (dist[np] != 0)
          continue;
        dist[np] = 1;
        sum += 1;
        que.push(np);
      }
    }
    Max = max(sum, Max);
  }
  cout << Max;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
vector<int> arr[1000000];
int vis[1000000];

int dfs(int v) {
  int ans = 0;
  ans++;
  vis[v] = 1;
  for (int child : arr[v]) {
    if (!vis[child])
      ans += dfs(child);
  }
  return ans;
}

int main() {
  std::ios::sync_with_stdio(false);
  int n, m, a, b;
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }
  int maxans = INT_MIN, ans;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ans = dfs(i);
      if (ans > maxans)
        maxans = ans;
    }
  }
  cout << maxans;
  return 0;
}


Error: WA

Fixed submission:


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
vector<int> arr[10001];
vector<int> primes;
int vis[10001];

int bfs(int src) {
  queue<int> q;
  vis[src] = 1;
  q.push(src);
  int count = 0;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    count++;
    for (int child : arr[curr]) {
      if (vis[child] == 0) {
        q.push(child);
        vis[child] = 1;
      }
    }
  }
  return count;
}

int main() {
  std::ios::sync_with_stdio(false);
  int T;
  // cin>>T;
  T = 1;
  // cin.ignore(); must be there when using getline(cin, s)
  while (T--) {
    int n, m, a, b;
    cin >> n >> m;
    while (m--) {
      cin >> a >> b;
      arr[a].push_back(b);
      arr[b].push_back(a);
    }
    int maxvalue = 0, ans = 1;
    for (int i = 1; i <= n; i++) {
      if (vis[i] == 0) {
        ans = bfs(i);
      }
      if (ans > maxvalue)
        maxvalue = ans;
    }
    cout << maxvalue;
  }
  return 0;
}
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++)
struct UnionFind {
  vector<int> d;                     // データ
  UnionFind(int n = 0) : d(n, -1) {} // 初期値は全部根(-1)とする
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) { // 2つ頂点をくっつける
    x = find(x);
    y = find(y);
    if (x == y)
      return false; // 一致していればOK
    if (d[x] > d[y])
      swap(x, y); // サイズが大きいものをxとする（根は負なので大小関係に注意）
    d[x] += d[y]; // サイズの合算
    d[y] = x;     // 根をxとする
    return false;
  }
  bool same(int x, int y) { // 同じ集合に属しているかを判定する
    return find(x) == find(y);
  }
  int size(int x) { // サイズを求める（根はマイナスなので、マイナスをとる）
    return -d[find(x)];
  }
};
int deg[200200];
vector<int> to[200200];
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a, b);
  }
  int saidai = 0;
  rep(i, n) { saidai = max(saidai, uf.size(i)); }
  cout << saidai << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct UnionFind {
  vector<int> d;                     // データ
  UnionFind(int n = 0) : d(n, -1) {} // 初期値は全部根(-1)とする
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) { // 2つ頂点をくっつける
    x = find(x);
    y = find(y);
    if (x == y)
      return false; // 一致していればOK
    if (d[x] > d[y])
      swap(x, y); // サイズが大きいものをxとする（根は負なので大小関係に注意）
    d[x] += d[y]; // サイズの合算
    d[y] = x;     // 根をxとする
    return false;
  }
  bool same(int x, int y) { // 同じ集合に属しているかを判定する
    return find(x) == find(y);
  }
  int size(int x) { // サイズを求める（根はマイナスなので、マイナスをとる）
    return -d[find(x)];
  }
};
int deg[100005];
vector<int> to[100005];
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a, b);
  }
  int saidai = 0;
  rep(i, n) { saidai = max(saidai, uf.size(i)); }
  cout << saidai << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n, m;
struct dsu {
  int g[N];
  int size[N];
  int max_ = 1;
  void init() {
    for (int i = 0; i < n; i++)
      g[i] = i, size[i] = 1;
  }
  int find(int x) { return x == g[x] ? x : g[x] = find(g[x]); }
  void uni(int x, int y) {
    int px = find(x), py = find(y);
    if (px != py) {
      if (size[px] < size[py])
        swap(px, py);
      size[px] += size[py];
      size[py] = 0;
      g[py] = g[px];
      max_ = max(max_, size[px]);
    }
  }
} dis;

int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m;
  dis.init();
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    dis.uni(--a, --b);
  }
  cout << dis.max_ << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
struct dsu {
  int g[N];
  int size[N];
  int max_ = 1;
  void init() {
    for (int i = 0; i < N; i++)
      g[i] = i, size[i] = 1;
  }
  int find(int x) { return x == g[x] ? x : g[x] = find(g[x]); }
  int uni(int x, int y) {
    int px = find(x), py = find(y);
    if (px != py) {
      size[px] += size[py];
      size[py] = 0;
      g[py] = g[px];
      max_ = max(max_, size[px]);
    }
  }
} dis;

int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  dis.init();
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    dis.uni(--a, --b);
  }
  cout << dis.max_ << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

using namespace std;
#include <bits/stdc++.h>
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long
#define debug(x) cout << #x << " = " << x << endl
vector<int> adj[200001];
bool visited[200001];
int val;
void dfs(int p) {
  visited[p] = true;
  val++;
  for (auto it = adj[p].begin(); it < adj[p].end(); it++) {
    if (!visited[*it]) {
      dfs(*it);
    }
  }
}
void solve() {
  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 = 0; i < n; i++) {
    unique(adj[i].begin(), adj[i].end());
  }
  // now run the dfs
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      dfs(i);
      ans = max(ans, val);
      val = 0;
    }
  }
  cout << ans << endl;
}
int main() {
  FASTIO
  long long int t = 1;
  while (t--)
    solve();
  return 0;
}


Error: 0

Fixed submission:

using namespace std;
#include <bits/stdc++.h>
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long
#define debug(x) cout << #x << " = " << x << endl
vector<int> adj[100001];
bool visited[100001];
int val;
void dfs(int p) {
  visited[p] = true;
  val++;
  for (auto it = adj[p].begin(); it < adj[p].end(); it++) {
    if (!visited[*it]) {
      dfs(*it);
    }
  }
}
void solve() {
  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 = 0; i < n; i++) {
    unique(adj[i].begin(), adj[i].end());
  }
  // now run the dfs
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      dfs(i);
      ans = max(ans, val);
      val = 0;
    }
  }
  cout << ans << endl;
}
int main() {
  FASTIO
  long long int t = 1;
  while (t--)
    solve();
  return 0;
}