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

/*----------------------------------------------------*
 * लेखक --> अमित सिंह
 * संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
 *-----------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define endl "\\n"
#define MOD 1000000007
void Tez() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
map<int, list<int>> adj;
map<int, bool> vis;
int dfs(int ver) {
  int ans = 0;
  if (!vis[ver]) {
    vis[ver] = 1;
    ans++;
    for (auto ngr : adj[ver]) {
      ans += dfs(ngr);
    }
  }
  return ans;
}
int main() {
  Tez();
  int n, m;
  cin >> n >> m;
  fo(i, m) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (auto nodes : adj)
    vis[nodes.first] = false;
  int ans = 1;
  for (auto nodes : adj) {
    if (!vis[nodes.first])
      ans = max(ans, dfs(nodes.first));
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

/*----------------------------------------------------*
 * लेखक --> अमित सिंह
 * संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
 *-----------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define endl "\\n"
#define MOD 1000000007
void Tez() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  Tez();
  int n, m;
  cin >> n >> m;
  vector<set<int>> v;
  int t = m - 1;
  int a, b;
  cin >> a >> b;
  if (m > 0) {
    set<int> s;
    s.insert(a);
    s.insert(b);
    v.push_back(s);
  }
  while (t > 0) {
    cin >> a >> b;
    for (int i = 0; i < v.size(); i++) {
      if ((v[i].find(a) != v[i].end()) || (v[i].find(b) != v[i].end())) {
        v[i].insert(a);
        v[i].insert(b);
      } else {
        set<int> s;
        s.insert(a);
        s.insert(b);
        v.push_back(s);
      }
    }
    t--;
  }
  vector<int> arr(v.size());
  int sz = 0;
  for (int i = 0; i < v.size(); i++) {
    arr[i] = (int)v[i].size() - 1;
    sz += arr[i];
  }
  int ans = 0;
  ans = *max_element(arr.begin(), arr.end());
  sz = n - sz;
  if (sz > 0)
    ans += 1;
  cout << ans;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define IO                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
const int MOD = 1e9 + 7;
int dsu[200005];
int getParent(int num) {
  if (dsu[num] == num)
    return num;
  return dsu[num] = getParent(dsu[num]);
}
void makeParent(int a, int b) {
  a = getParent(a);
  b = getParent(b);
  dsu[a] = b;
}
int main() {
  IO;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    dsu[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    makeParent(a, b);
  }
  map<int, int> dd;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    dd[getParent(i)]++;
    ans = max(ans, dd[getParent(i)]);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define IO                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
const int MOD = 1e9 + 7;
int dsu[200005];
int getParent(int num) {
  if (dsu[num] == num)
    return num;
  return dsu[num] = getParent(dsu[num]);
}
int makeParent(int a, int b) {
  a = getParent(a);
  b = getParent(b);
  dsu[a] = b;
}
int main() {
  IO;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    dsu[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    makeParent(a, b);
  }
  map<int, int> dd;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    dd[getParent(i)]++;
    ans = max(ans, dd[getParent(i)]);
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

void dfs(vector<vector<int>> &graph, int &num, int node,
         vector<bool> &visited) {
  visited[node] = true;
  num++;
  for (auto x : graph[node]) {
    if (!visited[x]) {
      dfs(graph, num, x, visited);
    }
  }
}
int biggest_comp(vector<vector<int>> &graph, int n) {
  int maxi = 0;
  vector<bool> visited(n + 1, false);
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      int num = 0;
      dfs(graph, num, i, visited);
      if (num > maxi)
        maxi = num;
    }
  }
  return maxi;
}

int main() {
  // freopen("input.in", "r", stdin);
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  cout << biggest_comp(graph, n);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void dfs(vector<vector<int>> graph, int &num, int node, vector<bool> &visited) {
  visited[node] = true;
  num++;
  for (auto x : graph[node]) {
    if (!visited[x]) {
      dfs(graph, num, x, visited);
    }
  }
}
int biggest_comp(vector<vector<int>> graph, int n) {
  int maxi = 0;
  vector<bool> visited(n + 1, false);
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      int num = 0;
      dfs(graph, num, i, visited);
      if (num > maxi)
        maxi = num;
    }
  }
  return maxi;
}

int main() {
  // freopen("input.in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  cout << biggest_comp(graph, n);
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(string s = "") {
  unsyncIO();
  if (s.size()) {
    setIn(s + ".in");
    setOut(s + ".out");
  }
}

#define ll long long
const ll mod = 1e9 + 7;
const int MX = 200005;

int n, m;
int par[MX], sz[MX];

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

int main() {
  // setIO();

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
  for (int u, v, i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    u = f(u);
    v = f(v);
    if (u != v) {
      if (u < v)
        swap(u, v);
      sz[v] += sz[u], par[u] = v;
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (par[i] == i)
      ans = max(ans, sz[i]);
  printf("%d\\n", ans);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(string s = "") {
  unsyncIO();
  if (s.size()) {
    setIn(s + ".in");
    setOut(s + ".out");
  }
}

#define ll long long
const ll mod = 1e9 + 7;
const int MX = 200005;

int n, m;
vector<int> adj[MX];
int par[MX], sz[MX];

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

int main() {
  setIO();

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
  for (int u, v, i = 0; i < m; i++) {
    cin >> u >> v;
    u = f(u);
    v = f(v);
    if (u != v)
      sz[v] += sz[u], par[u] = v;
  }

  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = max(ans, sz[i]);
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define LL long long int
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
const int N = 2e5 + 5;
const int oo = 1e9 + 5;
const LL ooll = (LL)1e18 + 5;
const int MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng)

clock_t start = clock();

vector<int> g[N];
int viscnt, vis[N];
void dfs(int node) {
  vis[node] = 1;
  viscnt++;
  for (auto it : g[node])
    if (!vis[it]) {
      dfs(it);
    }
}

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    g[i].clear();
    vis[i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      viscnt = 0;
      dfs(i);
      ans = max(ans, viscnt);
    }
  cout << ans << '\\n';
}

int main() {
  FASTIO;
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  // cerr << fixed << setprecision(10);
  // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define LL long long int
#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
const int N = 1e5 + 5;
const int M = 21;
const int oo = 1e9 + 5;
const LL ooll = (LL)1e18 + 5;
const int MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng)

clock_t start = clock();

vector<int> g[N];
int viscnt, vis[N];
void dfs(int node) {
  vis[node] = 1;
  viscnt++;
  for (auto it : g[node])
    if (!vis[it]) {
      dfs(it);
    }
}

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    g[i].clear();
    vis[i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      viscnt = 0;
      dfs(i);
      ans = max(ans, viscnt);
    }
  cout << ans << '\\n';
}

int main() {
  FASTIO;
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  // cerr << fixed << setprecision(10);
  // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\\n';
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
const int MOD = 1000000007;
using namespace std;
int vis[200005];
int cc = 0;
vector<int> arr[200005];
void dfs(int node) {
  cc++;
  vis[node] = 1;
  for (int child : arr[node]) {
    if (vis[child] == 0)
      dfs(child);
  }
}
int main() {

  int ans = 1;
  int n, m;
  int a, b;
  cin >> n >> m;

  while (m--) {
    cin >> a >> b;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {

    if (vis[i] == 0) {
      cc = 0;
      dfs(i);
      ans = max(ans, cc);
    }
  }
  cout << ans << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
const int MOD = 1000000007;
using namespace std;
int vis[100005];
int cc = 0;
vector<int> arr[100005];
void dfs(int node) {
  cc++;
  vis[node] = 1;
  for (int child : arr[node]) {
    if (vis[child] == 0)
      dfs(child);
  }
}
int main() {

  int ans = 1;
  int n, m;
  int a, b;
  cin >> n >> m;

  while (m--) {
    cin >> a >> b;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {

    if (vis[i] == 0) {
      cc = 0;
      dfs(i);
      ans = max(ans, cc);
    }
  }
  cout << ans << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
class dsu {
private:
public:
  vector<int> arr;
  vector<int> rank;
  dsu(int n) {
    arr.resize(n + 1);
    rank.resize(n + 1);
    init();
  }
  void init() {
    for (int i = 0; i < arr.size(); i++)
      arr[i] = i, rank[i] = 1;
  }
  int root(int a) {
    while (a != arr[a]) {
      arr[a] = arr[arr[a]];
      a = arr[a];
    }
    return a;
  }
  void unin(int a, int b) {
    int x = root(a);
    int y = root(b);
    if (x == y)
      return;
    if (rank[x] < rank[y]) {
      arr[x] = y;
      rank[y] += rank[x];
    } else {
      arr[y] = x;
      rank[x] += rank[y];
    }
  }
  bool find(int a, int b) {
    if (root(a) == root(b))
      return true;
    else
      return false;
  }
};
int main() {
  int n, m, a, b;
  cin >> n >> m;
  dsu d(n);
  while (m--) {
    cin >> a >> b;
    d.unin(a - 1, b - 1);
  }
  //	for(int i=0;i<d.rank.size();i++)
  //	cout<<d.rank[i]<<" ";
  //	cout<<endl;
  cout << *max_element(d.rank.begin(), d.rank.end()) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define FLSH fflush(stdout)
#define fileIO(name)                                                           \\
  freopen(name ".in", "r", stdin);                                             \\
  freopen(name ".out", "w", stdout);
#define PRECISION(x) cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI = acos(-1);

const int INF = 1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------

vector<ll> graph[200005];
vector<bool> vis(100005);
ll cnt = 0;
void dfs(ll src) {
  vis[src] = true;
  cnt++;
  int sz = graph[src].size();
  for (int i = 0; i < sz; i++) {
    if (!vis[graph[src][i]])
      dfs(graph[src][i]);
  }
}
void solve() {
  ll n, m;
  cin >> n >> m;
  ll a, b;
  set<pair<ll, ll>> st;
  for (ll i = 0; i < m; i++) {
    cin >> a >> b;
    if (st.find({a, b}) == st.end() || st.find({b, a}) == st.end()) {
      graph[a].push_back(b);
      graph[b].push_back(a);
      st.insert({a, b});
      st.insert({b, a});
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    cnt = 0;
    if (vis[i] == false) {
      dfs(i);
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
}

int main() {
  IOS ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return (0);
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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() {
  int n, m;
  cin >> n >> m;

  UnionFind uf(n);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    uf.unite(--a, --b);
  }

  int res = 0;

  rep(i, n) res = max(res, uf.size(i));

  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, unordered_set<int>> groups;
  unordered_map<int, int> ids;
  int nextid = 1;

  rep(i, m) {
    int a, b;
    cin >> a >> b;

    if (ids[a] > 0 && ids[b] > 0 && ids[a] != ids[b]) {
      int er = ids[a];
      for (auto p : groups[ids[a]]) {
        ids[p] = ids[b];
        groups[ids[b]].insert(p);
      }
      groups.erase(er);
    } else if (ids[a] > 0) {
      ids[b] = ids[a];
      groups[ids[a]].insert(b);
    } else if (ids[b] > 0) {
      ids[a] = ids[b];
      groups[ids[b]].insert(a);
    } else {
      ids[a] = nextid;
      ids[b] = nextid;
      groups[nextid].insert(a);
      groups[nextid].insert(b);
      nextid++;
    }
  }

  int res = 1;

  for (auto g : groups) {
    // printf("group: %d\\n", g.first);
    // for (auto e : g.second) cout << e << endl;
    res = max(res, (int)g.second.size());
  }

  cout << res << endl;

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

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

#define FASTIO1 ios_base::sync_with_stdio(false)
#define FASTIO2 cin.tie(NULL), cout.tie(NULL)
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll power(ll x, ll y, ll p);
const ll inf = 999999999;
const ll mod = 1e9 + 7;
bool tc = false;
#define MAX 200005

vector<ll> adj[MAX];
vector<bool> visited(MAX, false);
ll number_of_node_visited;

void dfs(ll src) {
  visited[src] = true;
  number_of_node_visited++;
  // cout<<src<<" ";
  for (ll node : adj[src])
    if (visited[node] == false)
      dfs(node);
  // return;
}

void solve() {
  // scan edge and vertices
  ll n, m, u, v, ans = -inf;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  for (ll i = 1; i <= n; i++)
    if (visited[i] == false) {
      number_of_node_visited = 0;
      dfs(i);
      ans = max(ans, number_of_node_visited);
    }
  cout << ans;
}

int main() {
  FASTIO1;
  FASTIO2;
  clock_t start = clock();
  ll t = 1;
  if (tc)
    cin >> t;
  while (t--)
    solve();
  cerr << fixed << setprecision(6);
  cerr << (double)(clock() - start) / CLOCKS_PER_SEC << endl;
  return 0;
}

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}


Error: WA

Fixed submission:

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

#define FASTIO1 ios_base::sync_with_stdio(false)
#define FASTIO2 cin.tie(NULL), cout.tie(NULL)
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll power(ll x, ll y, ll p);
const ll inf = 999999999;
const ll mod = 1e9 + 7;
bool tc = false;

vector<ll> adj[25];
vector<bool> visited(25, false);
ll number_of_node_visited;

void dfs(ll src) {
  visited[src] = true;
  number_of_node_visited++;
  // cout<<src<<" ";
  for (ll node : adj[src])
    if (visited[node] == false)
      dfs(node);
  // return;
}

void solve() {
  // scan edge and vertices
  ll n, m, u, v, ans = -inf;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  for (ll i = 1; i <= n; i++)
    if (visited[i] == false) {
      number_of_node_visited = 0;
      dfs(i);
      ans = max(ans, number_of_node_visited);
    }
  cout << ans;
}

int main() {
  FASTIO1;
  FASTIO2;
  clock_t start = clock();
  ll t = 1;
  if (tc)
    cin >> t;
  while (t--)
    solve();
  cerr << fixed << setprecision(6);
  cerr << (double)(clock() - start) / CLOCKS_PER_SEC << endl;
  return 0;
}

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005], f[200005], t[200005];
int find_(int x) {
  if (f[x] != x)
    f[x] = find_(f[x]);
  return f[x];
}
bool cmp(int x, int y) { return x > y; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    f[i] = i;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    int xx = find_(a[i]);
    int yy = find_(b[i]);
    if (xx != yy)
      f[yy] = xx;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    t[find_(i)]++;
  }
  sort(t + 1, t + 1 + n, cmp);
  cout << t[1] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], f[100005], t[100005];
int find_(int x) {
  if (f[x] != x)
    f[x] = find_(f[x]);
  return f[x];
}
bool cmp(int x, int y) { return x > y; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    f[i] = i;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    int xx = find_(a[i]);
    int yy = find_(b[i]);
    if (xx != yy)
      f[yy] = xx;
  }
  for (int i = 1; i <= n; i++) {
    f[i] = find_(f[i]);
  }
  sort(f + 1, f + 1 + n);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (f[i] != f[i + 1] && i + 1 <= n)
      continue;
    else
      t[f[i]]++;
  }
  sort(t + 1, t + 1 + n, cmp);
  cout << t[1] << endl;
  return 0;
}