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

#include <bitset>
#include <iostream>
#include <vector>
using namespace std;

int N, M;
vector<int> friends;

int root(int x) {
  if (friends.at(x) == x)
    return x;
  else
    return friends.at(x) = root(friends.at(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;

  friends.at(x) = y;
}

int main() {
  cin >> N >> M;
  friends.resize(N);
  for (int i = 0; i < N; i++) {
    friends.at(i) = i;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    unite(a - 1, b - 1);
  }
  vector<int> count(N);
  for (int i = 0; i < N; i++) {
    count.at(root(i))++;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (ans < count.at(i))
      ans = count.at(i);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> friends(N + 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    bool flag = true;
    for (int j = 0; j < friends.at(a).size(); j++) {
      if (b == friends.at(a).at(j)) {
        flag = false;
        break;
      }
    }
    if (flag) {
      friends.at(a).push_back(b);
      friends.at(b).push_back(a);
    }
  }
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < friends.at(i).size(); j++) {
      for (int k = 0; k < friends.at(friends.at(i).at(j)).size(); k++) {
        if (friends.at(friends.at(i).at(j)).at(k) != i) {
          bool flag = true;
          for (int l = 0; l < friends.at(i).size(); l++) {
            if (friends.at(friends.at(i).at(j)).at(k) == friends.at(i).at(l)) {
              flag = false;
              break;
            }
          }
          if (flag)
            friends.at(i).push_back(friends.at(friends.at(i).at(j)).at(k));
        }
      }
    }
  }
  int MAX = 0;
  for (int i = 0; i < friends.size(); i++) {
    if (MAX < friends.at(i).size())
      MAX = friends.at(i).size();
  }
  cout << MAX + 1 << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
// using u64 = int;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

int main(int argc, char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<vector<int>> g(N);
  for (int i = 0; i < M; i++) {
    int p, q;
    cin >> p >> q;
    p--, q--;
    g[p].push_back(q);
    g[q].push_back(p);
  }
  vector<int> visited(N, 0);
  int depth = 0;
  function<void(int, int)> dfs = [&](int i, int parent) {
    if (!visited[i]) {
      visited[i] = 1;
      depth++;
      // cout << depth << endl;
    }
    for (int j : g[i])
      if (j != parent && !visited[j]) {
        dfs(j, i);
      }
  };
  int max_value = 0;
  for (int i = 0; i < N; i++) {
    if (!visited[i]) {
      dfs(i, -1);
      max_value = max(max_value, depth);
      depth = 0;
    }
  }

  cout << max_value << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
// using u64 = int;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

int main(int argc, char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<vector<int>> g(N);
  for (int i = 0; i < M; i++) {
    int p, q;
    cin >> p >> q;
    p--, q--;
    g[p].push_back(q);
    g[q].push_back(p);
  }
  vector<int> visited(N, 0);
  int depth = 0;
  function<void(int, int)> dfs = [&](int i, int parent) {
    if (!visited[i]) {
      visited[i] = 1;
      depth++;
    }
    for (int j : g[i])
      if (j != parent) {
        dfs(j, i);
      }
  };
  int max_value = 0;
  for (int i = 0; i < N; i++) {
    if (!visited[i]) {
      dfs(i, -1);
      max_value = max(max_value, depth);
      depth = 0;
    }
  }

  cout << max_value << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long ll;
#define fr(i, k, n) for (ll i = k; i < n; i++)
#define mo map<ll, ll>
#define mod 1000000007
unordered_map<ll, vector<ll>> ms;
ll cd = 1;

ll dfs(ll j, bool visited[]) {
  visited[j] = true;
  for (auto it = ms[j].begin(); it != ms[j].end(); it++) {
    if (!visited[*it]) {
      cd++;
      dfs(*it, visited);
    }
  }
  return cd;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m;
  cin >> n >> m;

  ll x, y;
  bool visited[n + 2];
  memset(visited, false, sizeof(visited));
  fr(i, 0, m) {
    cin >> x >> y;
    ms[x].push_back(y);
    ms[y].push_back(x);
  }
  ll ans = LLONG_MIN;
  fr(i, 1, n + 1) {
    if (!visited[i]) {
      ans = max(dfs(i, visited), ans);
    }

    cd = 1;
  }
  ans = max(ans, ll(1));
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i, k, n) for (ll i = k; i < n; i++)
#define mo map<ll, ll>
#define mod 1000000007
bool visited[2 * 100000 + 2];
ll cd = 1;
ll dfs(map<ll, vector<ll>> ms, ll j) {
  visited[j] = true;
  for (auto it = ms[j].begin(); it != ms[j].end(); it++) {
    if (!visited[*it]) {
      cd++;
      dfs(ms, *it);
    }
  }
  return cd;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m;
  cin >> n >> m;
  map<ll, vector<ll>> ms;
  ll x, y;
  fr(i, 0, m) {
    cin >> x >> y;
    ms[x].push_back(y);
    ms[y].push_back(x);
  }
  ll ans = LLONG_MIN;
  fr(i, 1, n + 1) {
    if (!visited[i]) {
      ans = max(dfs(ms, i), ans);
    }

    cd = 1;
  }
  ans = max(ans, ll(1));
  cout << ans << "\\n";
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fr(i, n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<ll, ll>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define INF 1000000000
#define endl '\\n'
using namespace std;
vector<int> v[2000001];
vector<int> parent(2000001, -1);
int R[2000001] = {1};
ll ct = 0;
int find(int a) {
  // cout<<parent[a]<<endl;
  if (parent[a] < 0)
    return a;
  return parent[a] = find(parent[a]);
}
void u(int a, int b) {
  // cout<<a<<b<<endl;
  parent[a] = -(abs(parent[a]) + abs(parent[b]));
  // cout<<parent[a]<<endl;
  if (R[a] >= R[b]) {
    parent[b] = a;
    R[a] += R[b];
  } else {
    parent[a] = b;
    R[b] += R[a];
  }
  // Rank decrease we can find in o(logn) max time;
}
int main() {
  //	freopen("in4.txt", "r", stdin);
  //    freopen("output4.txt", "w", stdout);

  ll n, m, a, b;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    v[i].pb(i);
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    a = find(a);
    // cout<<a<<endl;
    b = find(b);
    // cout<<b<<endl;
    if (a != b)
      u(a, b);
  }
  int maxi = INT_MIN;
  for (int i = 1; i <= n; i++) {
    // cout<<parent[i]<<" ";
    if (parent[i] < 0) {
      maxi = max(maxi, abs(parent[i]));
    }
  }
  cout << maxi << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fr(i, n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<ll, ll>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define INF 1000000000
#define endl '\\n'
using namespace std;
vector<int> v[100001];
vector<int> parent(100001, -1);
int R[100001] = {1};
ll ct = 0;
int find(int a) {
  // cout<<parent[a]<<endl;
  if (parent[a] < 0)
    return a;
  return parent[a] = find(parent[a]);
}
void u(int a, int b) {
  // cout<<a<<b<<endl;
  parent[a] = -(abs(parent[a]) + abs(parent[b]));
  // cout<<parent[a]<<endl;
  if (R[a] >= R[b]) {
    parent[b] = a;
    R[a] += R[b];
  } else {
    parent[a] = b;
    R[b] += R[a];
  }
  // Rank decrease we can find in o(logn) max time;
}
int main() {
  //	freopen("in4.txt", "r", stdin);
  //    freopen("output4.txt", "w", stdout);

  ll n, m, a, b;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    v[i].pb(i);
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    a = find(a);
    // cout<<a<<endl;
    b = find(b);
    // cout<<b<<endl;
    if (a != b)
      u(a, b);
  }
  int maxi = INT_MIN;
  for (int i = 1; i <= n; i++) {
    // cout<<parent[i]<<" ";
    if (parent[i] < 0) {
      maxi = max(maxi, abs(parent[i]));
    }
  }
  cout << maxi << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <typename T> string join(vector<T> &vec, string &sp) {
  int si = vec.length;
  if (si == 0) {
    return "";
  } else {
    stringstream ss;
    rep(i, si - 1) { ss << vec[i] << sp; }
    ss << vec[si - 1];
    return ss.str();
  }
}
vector<int> uf(200010);
int root(int p) {
  if (p == uf[p])
    return p;
  else {

    return uf[p] = root(uf[p]);
  }
}
int main(void) {
  int n, m;
  cin >> n >> m;
  n++;
  rep(i, n + 1) { uf[i] = i; }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int rx = root(uf[a]);
    int ry = root(uf[b]);
    if (rx != ry) {
      uf[rx] = ry;
    }
  }
  unordered_map<int, int> mp;
  rep(i, n) {
    int p = root(i);
    if (!mp[p]) {
      mp[p] = 1;
    } else {
      mp[p]++;
    }
  }
  int max = 0;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    if (max < i->second)
      max = i->second;
  }
  cout << max << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <typename T> string join(vector<T> &vec, string &sp) {
  int si = vec.length;
  if (si == 0) {
    return "";
  } else {
    stringstream ss;
    rep(i, si - 1) { ss << vec[i] << sp; }
    ss << vec[si - 1];
    return ss.str();
  }
}
vector<int> uf(200010);
int root(int p) {
  if (p == uf[p])
    return p;
  else
    return root(uf[p]);
}
int main(void) {
  int n, m;
  cin >> n >> m;
  n++;
  rep(i, n + 1) { uf[i] = i; }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int rx = root(uf[a]);
    int ry = root(uf[b]);
    if (rx != ry) {
      uf[rx] = ry;
    }
  }
  unordered_map<int, int> mp;
  rep(i, n) {
    int p = root(i);
    if (!mp[p]) {
      mp[p] = 1;
    } else {
      mp[p]++;
    }
  }
  int max = 0;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    if (max < i->second)
      max = i->second;
  }
  cout << max << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

class DisjoinSet {
public:
  vector<int> p, r;

  DisjoinSet() {}
  DisjoinSet(int size) {
    r.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++)
      makeSet(i);
  }

  void makeSet(int x) {
    p[x] = x;
    r[x] = 0;
  }

  bool same(int x, int y) { return findSet(x) == findSet(y); }

  void unite(int x, int y) { link(findSet(x), findSet(y)); }

  void link(int x, int y) {
    if (r[x] > r[y])
      p[y] = x;
    else {
      p[x] = y;
      if (r[x] == r[y])
        r[y]++;
    }
  }

  int findSet(int x) {
    if (x != p[x])
      p[x] = findSet(p[x]);
    return p[x];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> k;
  DisjoinSet ds = DisjoinSet(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ds.unite(a, b);
  }
  for (int i = 0; i < n; i++) {
    int s = ds.findSet(i);
    k[s]++;
  }
  int ans = 0;
  for (auto p : k) {
    ans = max(ans, p.second);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

class DisjoinSet {
public:
  vector<int> p, r;

  DisjoinSet() {}
  DisjoinSet(int size) {
    r.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++)
      makeSet(i);
  }

  void makeSet(int x) {
    p[x] = x;
    r[x] = 0;
  }

  bool same(int x, int y) { return findSet(x) == findSet(y); }

  void unite(int x, int y) { link(findSet(x), findSet(y)); }

  void link(int x, int y) {
    if (r[x] > r[y])
      p[y] = x;
    else {
      p[x] = y;
      if (r[x] == r[y])
        r[y]++;
    }
  }

  int findSet(int x) {
    if (x != p[x])
      p[x] = findSet(p[x]);
    return p[x];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> k;
  DisjoinSet ds = DisjoinSet(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (!ds.same(a, b))
      ds.unite(a, b);
  }
  for (int i = 0; i < n; i++) {
    int s = ds.findSet(i + 1);
    k[s]++;
  }
  int ans = 0;
  for (auto p : k) {
    ans = max(ans, p.second);
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int dfs(int i, vector<bool> &visited, std::map<int, std::set<int>> &friends) {
  int result = 1;
  for (std::set<int>::iterator it = friends[i].begin(); it != friends[i].end();
       ++it) {
    if (!visited[*it]) {
      visited[*it] = true;
      result += dfs(*it, visited, friends);
    }
  }
  return result;
}

int main() {
  int n = 0;
  int m = 0;
  int a = 0;
  int b = 0;
  scanf("%d %d", &n, &m);
  vector<bool> visited(n, false);
  std::map<int, std::set<int>> friends;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    friends[a - 1].insert(b - 1);
    friends[b - 1].insert(a - 1);
  }
  int max_size = 1;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      visited[i] = true;
      int size = dfs(i, visited, friends);
      max_size = std::max(size, max_size);
      //      printf("%d\\n", i);
    }
  }
  printf("%d\\n", max_size);

  //  for(int i=0; i<n; i++){
  //    for(int j=0; j<k+1; j++){
  //      printf("%lld ", arr[i][j]);
  //    }
  //    printf("\\n");
  //  }
  //  printf("%lld\\n", (arr[n-1][k] - arr[n-1][k-1] + base) % base);
}


Error: TLE

Fixed submission:

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

int dfs(int i, vector<bool> &visited, std::map<int, std::set<int>> friends) {
  int result = 1;
  for (std::set<int>::iterator it = friends[i].begin(); it != friends[i].end();
       ++it) {
    if (!visited[*it]) {
      visited[*it] = true;
      result += dfs(*it, visited, friends);
    }
  }
  return result;
}

int main() {
  int n = 0;
  int m = 0;
  int a = 0;
  int b = 0;
  scanf("%d %d", &n, &m);
  vector<bool> visited(n, false);
  std::map<int, std::set<int>> friends;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    friends[a - 1].insert(b - 1);
    friends[b - 1].insert(a - 1);
  }
  int max_size = 1;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      visited[i] = true;
      int size = dfs(i, visited, friends);
      max_size = std::max(size, max_size);
      //      printf("%d\\n", i);
    }
  }
  printf("%d\\n", max_size);

  //  for(int i=0; i<n; i++){
  //    for(int j=0; j<k+1; j++){
  //      printf("%lld ", arr[i][j]);
  //    }
  //    printf("\\n");
  //  }
  //  printf("%lld\\n", (arr[n-1][k] - arr[n-1][k-1] + base) % base);
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.1415926535
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define Summon_Tourist                                                         \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll inf = 1e9 + 7;
ll modexp(ll base, ll power) {
  if (power == 0)
    return 1;
  if (power & 1)
    return base * modexp(base, power - 1) % inf;
  return modexp(base * base % inf, power / 2);
}
vector<ll> a[200005];
vector<ll> visited(200005, 0), weights(200005, 1);
ll dfs(ll x) {
  if (visited[x])
    return 0;
  visited[x] = 1;
  ll ret = weights[x];
  for (auto it : a[x]) {
    if (visited[it])
      continue;
    ret += dfs(it);
  }
  return ret;
}
int main() {
  Summon_Tourist
      // freopen("input.txt" , "r" , stdin ) ;
      ll t = 1;
  // cin>>t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
      ll x, y;
      cin >> x >> y;
      a[x].push_back(y);
      a[y].push_back(x);
    }
    ll ans = -1;
    for (ll i = 1; i <= n; i++) {
      if (visited[i] != 1) {
        ll ret = dfs(i);
        ans = max(ans, ret);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.1415926535
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define Summon_Tourist                                                         \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll inf = 1e9 + 7;
ll modexp(ll base, ll power) {
  if (power == 0)
    return 1;
  if (power & 1)
    return base * modexp(base, power - 1) % inf;
  return modexp(base * base % inf, power / 2);
}
vector<ll> a[20005];
vector<ll> visited(20005, 0), weights(20005, 1);
ll dfs(ll x) {
  if (visited[x])
    return 0;
  visited[x] = 1;
  ll ret = weights[x];
  for (auto it : a[x]) {
    if (visited[it])
      continue;
    ret += dfs(it);
  }
  return ret;
}
int main() {
  Summon_Tourist
      // freopen("input.txt" , "r" , stdin ) ;
      ll t = 1;
  // cin>>t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
      ll x, y;
      cin >> x >> y;
      a[x].push_back(y);
      a[y].push_back(x);
    }
    ll ans = -1;
    for (ll i = 1; i <= n; i++) {
      if (visited[i] != 1) {
        ll ret = dfs(i);
        ans = max(ans, ret);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define li long int
#define ld long double
#define pb push_back
using namespace std;

vector<int> lis[200001];
bool vis[200001];

void dfs(int node, int &curr) {
  vis[node] = true;
  curr++;
  for (int x : lis[node]) {
    if (!vis[x]) {
      dfs(x, curr);
    }
  }
}

int main() {
  int n, m, a, b;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    lis[a].pb(b);
    lis[b].pb(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      int curr = 0;
      dfs(i, curr);
      ans = max(ans, curr);
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define li long int
#define ld long double
#define pb push_back
using namespace std;

vector<int> lis[100001];
bool vis[100001];

void dfs(int node, int &curr) {
  vis[node] = true;
  curr++;
  for (int x : lis[node]) {
    if (!vis[x]) {
      dfs(x, curr);
    }
  }
}

int main() {
  int n, m, a, b;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    lis[a].pb(b);
    lis[b].pb(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      int curr = 0;
      dfs(i, curr);
      ans = max(ans, curr);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define dbug printf("I am here\\n");
#define Fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define vs v.size()
#define sot(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define ii pair<int, int>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mpp make_pair
#define Okay 0
#define pi 3.14159

static ll int inf = 1e9;
const int cont = 10e6 + 7;
using namespace std;

bool vis[1000005];
vector<int> graph[1000005];
int cnt = 1;

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

void solve() {
  int n, m;
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    graph[a].pb(b);
    graph[b].pb(a);
  }
  memset(vis, 0, sizeof vis);
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
      ans = max(ans, cnt);
    }
    cnt = 1;
  }
  cout << ans << endl;
}
int main() {
  solve();
  return Okay;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define dbug printf("I am here\\n");
#define Fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define vs v.size()
#define sot(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define ii pair<int, int>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mpp make_pair
#define Okay 0
#define pi 3.14159

static ll int inf = 1e9;
const int cont = 10e6 + 7;
using namespace std;

bool vis[100005];
vector<int> graph[100005];
int cnt = 1;

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

void solve() {
  int n, m;
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    graph[a].pb(b);
    graph[b].pb(a);
  }
  memset(vis, 0, sizeof vis);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
      ans = max(ans, cnt);
    }
    cnt = 1;
  }
  cout << ans << endl;
}
int main() {
  solve();
  return Okay;
}