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

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
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;
}
struct UnionFind {
  vector<int> par;

  // 要素nで初期化
  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  // xが属する集合の根を返す
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  // xとyが同じ集合に属しているかを判定
  bool issame(int x, int y) { return root(x) == root(y); }

  // xが属する集合とyが属する集合をマージ
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (par[x] > par[y])
      swap(x, y); // 計算量が減るよ
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  // xが属する集合のサイズ
  int size(int x) { return -par[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    uf.merge(a, b);
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, uf.size(i));
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
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;
}
struct UnionFind {
  vector<int> par;

  // 要素nで初期化
  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  // xが属する集合の根を返す
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  // xとyが同じ集合に属しているかを判定
  bool issame(int x, int y) { return root(x) == root(y); }

  // xが属する集合とyが属する集合をマージ
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (par[x] > par[y])
      swap(x, y); // 計算量が減るよ
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  // xが属する集合のサイズ
  int size(int x) { return -par[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;
    uf.merge(a, b);
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, uf.size(i));
  }
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int mx = 200009;
ll mod = 1000000007;
ll a[mx];
/*
 int siz[mx];
 int par[mx];



 int parent(int i){
     while(i!=par[i]){
         i=par[i];
     }
     return i;
 }
 void unit(int x,int y){

     if(siz[x]<siz[y]){swap(x,y);}

         int par1=parent(x);
         int par2=parent(y);
     par[par2]=par1;
     siz[par1]+=siz[par2];


 }bool same(int a, int b) {
return parent(a) == parent(b);
}
*/
vector<int> edges[mx];
int visited[mx];
int dfs(int i) {
  if (visited[i]) {
    return 0;
  }
  visited[i] = 1;
  ll ans = 0;
  for (int j = 0; j < edges[i].size(); j++) {
    ans += dfs(edges[i][j]);
  }
  return ans + 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;

    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      ans = max(ans, dfs(i));
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int mx = 200009;
ll mod = 1000000007;
ll a[mx];
/*
 int siz[mx];
 int par[mx];



 int parent(int i){
     while(i!=par[i]){
         i=par[i];
     }
     return i;
 }
 void unit(int x,int y){

     if(siz[x]<siz[y]){swap(x,y);}

         int par1=parent(x);
         int par2=parent(y);
     par[par2]=par1;
     siz[par1]+=siz[par2];


 }bool same(int a, int b) {
return parent(a) == parent(b);
}
*/
vector<int> edges[100000];
int visited[mx];
int dfs(int i) {
  if (visited[i]) {
    return 0;
  }
  visited[i] = 1;
  ll ans = 0;
  for (int j = 0; j < edges[i].size(); j++) {
    ans += dfs(edges[i][j]);
  }
  return ans + 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;

    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      ans = max(ans, dfs(i));
    }
  }
  cout << ans;
}
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 INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define F first
#define S second
typedef long long ll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// isPrime
// modpow modinv
// getDigit
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
class UnionFind {
public:
  vector<int> par;
  vector<int> siz;

  UnionFind(int n) {
    siz = vector<int>(n, 1);
    par = vector<int>(n, -1);
  }

  int root(int x) {
    if (par[x] == -1) {
      return x; // 根
    } else {
      return par[x] = root(par[x]); // 経路圧縮
    }
  }
  bool same(int x, int y) { return root(x) == root(y); }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (siz[y] < siz[x])
      swap(x, y);
    siz[y] += siz[x];
    par[x] = y;
  }
  int size(int x) { return siz[x]; }
};
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  UnionFind uf(n);
  rep(i, m) {
    a[i]--;
    b[i]--;
    uf.unite(a[i], b[i]);
  }
  int ans = 0;
  rep(i, n) { ans = max(ans, uf.siz[i]); }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define F first
#define S second
typedef long long ll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// isPrime
// modpow modinv
// getDigit
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
class UnionFind {
public:
  vector<int> par;
  vector<int> siz;

  UnionFind(int n) {
    siz = vector<int>(n, 1);
    par = vector<int>(n, -1);
  }

  int root(int x) {
    if (par[x] == -1) {
      return x; // 根
    } else {
      return par[x] = root(par[x]); // 経路圧縮
    }
  }
  bool same(int x, int y) { return root(x) == root(y); }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (siz[y] < siz[x])
      swap(x, y);
    siz[y] += siz[x];
    par[x] = y;
  }
  int size(int x) { return siz[x]; }
};
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  UnionFind uf(n);
  rep(i, m) {
    a[i]--;
    b[i]--;
    uf.unite(a[i], b[i]);
  }
  int ans = 0;
  rep(i, m) { ans = max(ans, uf.siz[i]); }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

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;

  int a, b;

  UnionFind ud(N);
  rep(i, M) {
    cin >> a >> b;
    a -= 1;
    b -= 1;
    ud.unite(a, b);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int se = ud.size(i);
    ans = max(ans, se);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

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

  vector<int> A(M, 0);
  vector<int> B(M, 0);
  vector<vector<int>> AB(N, vector<int>(N, 0));
  vector<int> gp(N, -1);
  vector<int> sc(N, 0);

  int a, b;
  int grp_cnt = 0;
  rep(i, M) {
    cin >> a >> b;
    a -= 1;
    b -= 1;
    if (gp[a] != -1) {
      gp[b] = gp[a];
    } else if (gp[b] != -1) {
      gp[a] = gp[b];
    } else {
      gp[a] = grp_cnt;
      gp[b] = grp_cnt;
      grp_cnt += 1;
    }
  }

  int max_val = 0;
  for (int i = 0; i < N; ++i) {
    if (gp[i] != -1) {
      sc[gp[i]] += 1;
      max_val = max(max_val, sc[gp[i]]);
    }
  }

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

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

int find(int x) {
  while (p[x] != x) {
    p[x] = p[p[x]];
    x = p[x];
  }
  return x;
}

void merge(int x, int y) {
  int a = find(x);
  int b = find(y);
  if (a == b)
    return;
  if (sz[a] < sz[b]) {
    p[a] = b;
    sz[b] += sz[a];
  } else {
    p[b] = a;
    sz[a] += sz[b];
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) {
    p[i] = i;
    sz[i] = 1;
  }
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    merge(x - 1, y - 1);
  }
  int ans = 0;
  vector<int> counter(n);
  rep(i, n) counter[find(p[i])]++;
  rep(i, n) ans = max(counter[i], ans);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int find(int x) {
  int a = x;
  while (p[a] != a)
    a = p[a];
  int i = x, j;
  while (i != a) {
    j = p[a];
    p[i] = a;
    i = j;
  }
  return a;
}

void merge(int x, int y) {
  int a = find(x);
  int b = find(y);
  if (a != b)
    p[a] = b;
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) p[i] = i;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    merge(x - 1, y - 1);
  }
  int ans = 0;
  vector<int> counter(n);
  rep(i, n) counter[find(p[i])]++;
  rep(i, n) ans = max(counter[i], ans);
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, m, num, ans = 0;
vector<vector<int>> g(200010);
bool vis[200010];

void dfs(int v) {
  vis[v] = true;
  num++;
  for (int i = 0; i < g[v].size(); i++) {
    if (!vis[g[v][i]]) {
      dfs(g[v][i]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int a, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      num = 0;
      dfs(i);
      ans = max(ans, num);
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

void DFS(int n, int v, vector<vector<int>> arr, bool *visited, int &cnt) {
  visited[v] = true;
  cnt += 1;
  for (int i = 0; i < arr[v].size(); i++) {
    if (arr[v][i] != v && visited[arr[v][i]] == false) {
      DFS(n, arr[v][i], arr, visited, cnt);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, m, a, b;
  cin >> n >> m;
  vector<vector<int>> arr;
  bool *visited = new bool[n + 1]();
  for (int i = 0; i <= n; i++) {
    vector<int> temp;
    arr.push_back(temp);
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    arr[a].push_back(b);
    arr[b].push_back(a);
  }
  int maxNum = 0;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == false) {
      int cnt = 0;
      DFS(n, i, arr, visited, cnt);
      maxNum = max(cnt, maxNum);
    }
  }
  cout << maxNum;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

/****************************************************************************************************
                                        SUBMITTED BY-

                                            AISH_07

****************************************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI 3.14159265
#define mod 998244353
bool visited[200003];
vector<vector<int>> v(200003);
set<int> p;
int dfs(int e) {
  int sum = 0;
  for (int i = 0; i < v[e].size(); i++) {
    if (visited[v[e][i]] == false) {
      visited[v[e][i]] = true;
      sum += 1 + dfs(v[e][i]);
    }
  }
  return sum;
}

int main() {
  int n, m;
  cin >> n >> m;
  memset(visited, false, sizeof visited);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].pb(b);
    v[b].pb(a);
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    visited[i] = true;
    int d = 1 + dfs(i);
    if (d > sum)
      sum = d;
  }
  cout << sum << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

/****************************************************************************************************
                                        SUBMITTED BY-

                                            AISH_07

****************************************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI 3.14159265
#define mod 998244353
int dfs(vector<vector<int>> p, bool v[], int e) {
  int sum = 0;
  for (int i = 0; i < p[e].size(); i++) {
    if (v[p[e][i]] == false) {
      v[p[e][i]] = true;
      sum += 1 + dfs(p, v, p[e][i]);
    }
  }
  return sum;
}

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

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

  vector<vector<int>> v(n + 1);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].pb(b);
    v[b].pb(a);
  }
  int maxi = INT_MIN;
  for (int i = 1; i <= n; i++) {
    visited[i] = true;
    int d = 1 + dfs(v, visited, i);
    maxi = max(maxi, d);
    memset(visited, false, sizeof visited);
  }
  cout << maxi << "\\n";
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

// Deep Godhani
// DAIICT

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

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL))

void dfs(ll curr, vector<vector<ll>> &v, vector<bool> &vis, int &count) {
  vis[curr] = true;
  count++;

  for (int i = 0; i < (int)v[curr].size(); i++) {
    if (!vis[v[curr][i]]) {
      dfs(v[curr][i], v, vis, count);
    }
  }
}

void solve() {
  ll n, m;
  cin >> n >> m;

  vector<vector<ll>> v(n + 1);
  set<pair<ll, ll>> s;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (s.find({x, y}) != s.end()) {
      continue;
    }
    s.insert({x, y});
    v[x].push_back(y);
    v[y].push_back(x);
  }

  vector<bool> vis(n + 1, false);
  int ans = 0, count = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      count = 0;
      dfs(i, v, vis, count);
      ans = max(ans, count);
    }
  }

  cout << ans << endl;
}

int main() {
  FAST;
  ll t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

// Deep Godhani
// DAIICT

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

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL))

void dfs(ll curr, vector<vector<ll>> v, vector<bool> &vis, int &count) {
  vis[curr] = true;
  count++;

  for (int i = 0; i < v[curr].size(); i++) {
    if (!vis[v[curr][i]]) {
      dfs(v[curr][i], v, vis, count);
    }
  }
}

void solve() {
  ll n, m;
  cin >> n >> m;

  vector<vector<ll>> v(n + 1);
  set<pair<ll, ll>> s;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (s.find({x, y}) != s.end()) {
      continue;
    }
    s.insert({x, y});
    v[x].push_back(y);
    v[y].push_back(x);
  }

  vector<bool> vis(n + 1, false);
  int ans = 0, count = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      count = 0;
      dfs(i, v, vis, count);
      ans = max(ans, count);
    }
  }

  cout << ans << endl;
}

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

/**
 *    author:  RM07
 *    created: August 29, 2020 5:48 PM
 *    motto: Knowledge is Power, Strive for Excellence
 **/
#include <bits/stdc++.h>
using namespace std;
#define int long long
set<int> adj[200005];
bool visited[200005];
int cnt = 0;
void dfs(int vertex) {
  visited[vertex] = true;
  cnt++;
  for (auto child : adj[vertex]) {
    if (!visited[child]) {
      dfs(child);
    }
  }
}
signed main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    adj[a].insert(b);
    adj[b].insert(a);
    // graph build process.
  }
  memset(visited, false, n + 1);
  vector<int> v;
  v.push_back(INT_MIN);
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      cnt = 0;
      dfs(i);
      v.push_back(cnt);
    }
  }
  cout << *max_element(v.begin(), v.end()) << endl;
}

Error: 0

Fixed submission:

/**
 *    author:  RM07
 *    created: August 29, 2020 5:48 PM
 *    motto: Knowledge is Power, Strive for Excellence
 **/
#include <bits/stdc++.h>
using namespace std;
#define int long long
set<int> adj[200005];
bool visited[200005];
int cnt = 0;
void dfs(int vertex) {
  visited[vertex] = true;
  cnt++;
  for (auto child : adj[vertex]) {
    if (!visited[child]) {
      dfs(child);
    }
  }
}
signed main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    adj[a].insert(b);
    adj[b].insert(a);
    // graph build process.
  }
  memset(visited, false, n + 1);
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      cnt = 0;
      dfs(i);
      if (cnt > 1) {
        v.push_back(cnt);
      }
    }
  }
  cout << *max_element(v.begin(), v.end()) << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000079];
bool vis[1000009];
int cnt;

void dfs(int node) {
  if (vis[node] == 1)
    return;
  vis[node] = 1;
  cnt++;

  for (auto c : g[node])
    dfs(c);
}

int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {

      cnt = 0;
      dfs(i);
      mx = max(cnt, mx);
    }
  }
  cout << mx << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000000];
bool vis[100000];
int cnt;

void dfs(int node) {
  if (vis[node] == 1)
    return;
  vis[node] = 1;
  cnt++;

  for (auto c : g[node])
    dfs(c);
}

int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {

      cnt = 0;
      dfs(i);
      mx = max(cnt, mx);
    }
  }
  cout << mx << endl;
}