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

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define testcase                                                               \\
  ll T;                                                                        \\
  cin >> T;                                                                    \\
  for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 998244353
#define eps 1e-8
#define eq(x, y) (fabs((x) - (y)) < eps)
#define r2 1.41421356237
ll powmod(ll a, ll b, ll mod) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // testcase {
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1, -1);
  while (m--) {
    int c, d;
    cin >> c >> d;
    // if(v[p]==q || v[q]==p) { continue; }
    while (v[c] > 0) {
      c = v[c];
    }
    while (v[d] > 0) {
      d = v[d];
    }
    if (c == d) {
      continue;
    }
    if (v[c] < v[d]) {
      v[c] += v[d];
      v[d] = c;
    } else {
      v[d] += v[c];
      v[c] = d;
    }
  }
  int ans = M;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, v[i]);
  }
  cout << -ans;
  //}
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define testcase                                                               \\
  ll T;                                                                        \\
  cin >> T;                                                                    \\
  for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 998244353
#define eps 1e-8
#define eq(x, y) (fabs((x) - (y)) < eps)
#define r2 1.41421356237
ll powmod(ll a, ll b, ll mod) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // testcase {
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1, -1);
  while (m--) {
    int c, d;
    cin >> c >> d;
    // if(v[p]==q || v[q]==p) { continue; }
    while (v[c] > 0) {
      c = v[c];
    }
    while (v[d] > 0) {
      d = v[d];
    }
    if (c == d) {
      continue;
    }
    v[c] += v[d];
    v[d] = c;
  }
  int ans = M;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, v[i]);
  }
  cout << -ans;
  //}
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

// 자동 정렬은 ctrl k f
// 주석은 ctrl k c
// 주석 해제는 ctrl k u
//  int gcd(int a, int b){
//  	while(b!=0){
//  		int r= a%b;
//  		a=b;
//  		b=r;
//  	}
//  	return a;
//  }
//  int lcm(int a, int b){
//  	return a*b/gcd(a,b);
//  }
int arr[200001];
int save[200001];

int getParent(int x) {
  if (arr[x] == x) {
    return x;
  } else {
    return arr[x] = getParent(arr[x]);
  }
}

void find(int x, int y) {
  // int x_p = arr[x];
  int x_p = getParent(x);
  // int y_p = arr[y];
  int y_p = getParent(y);

  if (x_p != y_p) {
    if (x_p < y_p) {
      arr[y_p] = x_p;
    } else {
      arr[x_p] = y_p;
    }
  }
}

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

  int n, m;
  cin >> n >> m;

  for (int i = 1; i <= n; i++) {
    arr[i] = i;
  }

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    find(x, y);
  }

  for (int i = 1; i <= n; i++) {
    arr[i] = getParent(arr[i]);
    // cout << arr[i] << ' ';
  }

  for (int i = 1; i <= n; i++) {
    save[arr[i]]++;
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, save[i]);
  }
  cout << ans << '\\n';
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

// 자동 정렬은 ctrl k f
// 주석은 ctrl k c
// 주석 해제는 ctrl k u
//  int gcd(int a, int b){
//  	while(b!=0){
//  		int r= a%b;
//  		a=b;
//  		b=r;
//  	}
//  	return a;
//  }
//  int lcm(int a, int b){
//  	return a*b/gcd(a,b);
//  }
int arr[200001];
int save[200001];

int getParent(int x) {
  if (arr[x] == x) {
    return x;
  } else {
    getParent(arr[x]);
  }
}

void find(int x, int y) {
  // int x_p = arr[x];
  int x_p = getParent(x);
  // int y_p = arr[y];
  int y_p = getParent(y);

  if (x_p != y_p) {
    if (x_p < y_p) {
      arr[y] = x_p;
    } else {
      arr[x] = y_p;
    }
  }
}

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

  int n, m;
  cin >> n >> m;

  for (int i = 1; i <= n; i++) {
    arr[i] = i;
  }

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    find(x, y);
  }

  for (int i = 1; i <= n; i++) {
    save[arr[i]]++;
    cout << arr[i] << ' ';
  }

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

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);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    uf.unite(A, B);
  }
  int res = 0;
  for (int i = 0; i < N; ++i)
    res = max(res, uf.size(i));
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

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(M);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    uf.unite(--A, --B);
  }
  int res = 0;
  for (int i = 0; i < N; ++i)
    res = max(res, uf.size(i));
  cout << res << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

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);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    uf.unite(A, B);
  }

  int res = 0;
  for (int i = 0; i < N; ++i)
    res = max(res, uf.size(i));
  cout << res << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
  int N, M;
  cin >> N >> M;
  vector<set<ll>> vs;
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    if (vs.size()) {
      for (auto &&v : vs) {
        if (v.count(A)) {
          v.insert(B);
          continue;
        } else if (v.count(B)) {
          v.insert(A);
          break;
        } else {
          vs.push_back(set<ll>{A, B});
        }
      }
    } else {
      vs.push_back(set<ll>{A, B});
    }
  }
  sort(vs.begin(), vs.end());
  if (vs.size() == 0)
    cout << 1 << endl;
  else
    cout << vs[0].size() << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct UnionFind {
  vector<int> p;

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

  int root(int c) {
    if (p.at(c) < 0)
      return c;
    else
      return p.at(c) = root(p.at(c));
  }

  void unite(int a, int b) {
    int ra = root(a);
    int rb = root(b);
    if (ra == rb)
      return;
    if (p.at(ra) > p.at(rb))
      swap(p.at(ra), p.at(rb));
    p.at(ra) += p.at(rb);
    p.at(rb) = ra;
  }

  int size(int c) { return -p.at(root(c)); }
};

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

  UnionFind fuf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    fuf.unite(a - 1, b - 1);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, fuf.size(i));
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

struct UnionFind {
  vector<int> p;

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

  int root(int c) {
    if (p.at(c) < 0)
      return c;
    else
      return root(p.at(c));
  }

  void unite(int a, int b) {
    int ra = root(a);
    int rb = root(b);
    if (ra == rb)
      return;
    if (p.at(ra) > p.at(rb))
      swap(p.at(ra), p.at(rb));
    p.at(ra) += p.at(rb);
    p.at(rb) = ra;
  }

  int size(int c) { return -p.at(root(c)); }
};

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

  UnionFind fuf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    fuf.unite(a - 1, b - 1);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, fuf.size(i));
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int ssize[200005];
int find(int parent[], int i) {
  if (parent[i] != i)
    parent[i] = find(parent, parent[i]);
  return parent[i];
}

void Union(int parent[], int x, int y) {
  int xset = find(parent, x);
  int yset = find(parent, y);
  if (xset != yset) {
    parent[xset] = yset;
    ssize[yset] = ssize[yset] + ssize[xset];
  }
}

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

  ll N, M;
  cin >> N >> M;
  int *dsu = new int[N * sizeof(int)];
  // memset(dsu, -1, sizeof(int) * N);

  for (int i = 0; i < N; i++) {
    ssize[i] = 1;
    dsu[i] = i;
  }
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    Union(dsu, x - 1, y - 1);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, ssize[i]);
  }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

int ssize[200005];
int find(int parent[], int i) {
  if (parent[i] == -1)
    return i;
  return find(parent, parent[i]);
}

void Union(int parent[], int x, int y) {
  int xset = find(parent, x);
  int yset = find(parent, y);
  if (xset != yset) {
    parent[xset] = yset;
    ssize[yset] = ssize[yset] + ssize[xset];
  }
}

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

  ll N, M;
  cin >> N >> M;
  int *dsu = new int[N * sizeof(int)];
  memset(dsu, -1, sizeof(int) * N);
  // memset(ssize, 0, sizeof(int) * N);
  for (int i = 0; i < N; i++)
    ssize[i] = 1;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    Union(dsu, x - 1, y - 1);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, ssize[i]);
    // cout<<ssize[i]<<" ";
  }
  // cout<<endl;
  cout << ans << "\\n";
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define int long long

vector<int> graph[200005];
void add_edge(int u, int v) {
  graph[u].push_back(v);
  graph[v].push_back(u);
}

// Function to traverse the undirected graph
// using DFS algorithm and keep a track of
// individual lengths of connected chains
void depthFirst(int v, vector<int> graph[], vector<bool> &visited, int &ans) {
  // Marking the visited vertex as true
  visited[v] = true;

  // Incrementing the count of
  // connected chain length
  ans++;

  for (auto i : graph[v]) {
    if (visited[i] == false) {
      // Recursive call to the DFS algorithm
      depthFirst(i, graph, visited, ans);
    }
  }
}

// Function to initialize the graph
// and display the result
int UniqueConnectedComponent(int n, vector<int> graph[]) {
  int mx = -1;

  // Initializing boolean visited array
  // to mark visited vertices
  vector<bool> visited(n + 1, false);

  // Initializing a Set container
  unordered_set<int> result;

  // Following loop invokes DFS algorithm
  for (int i = 1; i <= n; i++) {
    if (visited[i] == false) {
      // ans variable stores the
      // individual counts
      int ans = 0;

      // DFS algorithm
      depthFirst(i, graph, visited, ans);

      // Inserting the counts of connected
      // components in set
      result.insert(ans);
      mx = max(mx, ans);
    }
  }
  return mx;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    add_edge(a, b);
  }
  cout << UniqueConnectedComponent(n, graph);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int sze = 2 * pow(10, 5);
int curr = 0;
vector<vector<int>> v(sze);

void dfs(vector<vector<int>> v, int src, bool vis[], int &mx) {
  vis[src] = true;
  curr++;
  mx = max(mx, curr);
  for (auto node : v[src])
    if (!vis[node])
      dfs(v, node, vis, mx);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  int x, y;
  v.resize(n);
  map<pair<int, int>, bool> mp;
  while (m--) {
    cin >> x >> y;
    x--;
    y--;

    if (mp[make_pair(x, y)] && mp[make_pair(y, x)])
      continue;

    mp[make_pair(x, y)] = true;
    mp[make_pair(y, x)] = true;
    v[x].push_back(y);
    v[y].push_back(x);
  }

  bool vis[n];
  for (int i = 0; i < n; i++)
    vis[i] = false;
  int mx = 0;

  for (int i = 0; i < n; i++) {
    if (!vis[i])
      dfs(v, 0, vis, mx);
    curr = 0;
  }
  cout << mx << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct UnionFind {
  // If the vertex is a parent, this value will be the number of vertices that
  // belongs to the set, multiplied by -1 Otherwise, this value will be the
  // parent's id
  vector<int> r;

  UnionFind(int N) { r = vector<int>(N, -1); }

  int root(int x) {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) { return -r[root(x)]; }
};

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

  // Make friends-sets
  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A -= 1;
    B -= 1;
    UF.unite(A, B);
  }

  // Find the maximum friends-set
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, UF.size(i));
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

#define ll long long
#define ld long double
#define mod 1000000007LL
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define pb(x) push_back(x)
#define fo(i, a, n) for (i = (a); i < (n); i++)
#define foe(i, a, n) for (i = (a); i <= (n); i++)
// clang-format off
#define vin(a) for (ll i = 0; i < sz(a); i++) { cin >> a[i]; } 
#define vout(a) for (auto x : a) { cout << x << " "; }
#define sws                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)
// clang-format on
#define pd(x) cout << x
#define sd(x) cin >> x
#define nl cout << endl
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define foreach(i, a)                                                          \\
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
// int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
ll find(vll &g, ll x) {
  while (g[x] != x) {
    x = g[x];
  }
  return x;
}

void Union(vll &g, ll a, ll b) {
  ll x = find(g, a);
  ll y = find(g, b);
  if (x > y)
    swap(x, y);
  g[y] = x;
}

void solve() {
  ll m, n;
  ll i, j;
  ll x, y;
  scanf("%lld%lld", &n, &m);
  vll group(n + 1);
  foe(i, 1, n) { group[i] = i; }

  fo(i, 0, m) {
    scanf("%lld%lld", &x, &y);
    Union(group, x, y);
  }
  unordered_map<ll, ll> count;

  ll ans = 0;
  fo(i, 1, n + 1) {
    count[find(group, i)]++;
    ans = max(ans, count[find(group, i)]);
  }
  printf("%lld", ans);
}

int main() {
  sws;
  solve();
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

vector<set<int>> graph;
vector<int> visited;
int sz;

void dfs(int u) {
  if (!visited[u]) {
    visited[u] = 1;
    ++sz;
  }
  for (auto v : graph[u]) {
    if (!visited[v]) {
      dfs(v);
    }
  }
}

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

  graph = vector<set<int>>(n, set<int>());
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    u--;
    v--;
    graph[u].insert(v);
    graph[v].insert(u);
  }

  visited = vector<int>(n);
  int groups = 0;
  for (int i = 0; i < n; i++) {
    sz = 0;
    if (!visited[i]) {
      dfs(i);
    }
    groups = max(groups, sz);
  }

  cout << groups << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> aa(n, 0);
  vector<vector<bool>> ab(n, vector<bool>(n, 0));
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    if (ab[a][b])
      continue;
    ab[a][b] = 1;
    ab[b][a] = 1;
    aa[min(a, b)]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(aa[i], ans);
  }
  cout << ++ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
    author:ujwalll
*/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const int INF = 1 << 29;
const int MOD = 1073741824;
#define pp pair<ll, ll>
#define ppi pair<int, int>
typedef long long int ll;
bool isPowerOfTwo(ll x) { return x && (!(x & (x - 1))); }
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
////////////////////////////////////////////////////////////////////
set<int> adj[200005];
bool vis[200005];
int cnt = 0;
void solve(int s) {
  vis[s] = 1;
  cnt++;
  for (auto i : adj[s]) {
    if (vis[i])
      continue;
    solve(i);
  }
}
int main() {
  int tc = 1;
  // cin>>tc;
  while (tc--) {
    memset(vis, 0, sizeof(vis));
    int n, m;
    cin >> n >> m;
    rep(i, m) {
      int x, y;
      cin >> x >> y;
      adj[x].insert(y);
      adj[y].insert(x);
    }
    int ans = 0;
    for1(i, n) {
      if (!vis[i]) {
        vis[i] = 1;
        solve(i);
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    cout << ans;
  }
  return 0;
}

Error: TLE

Fixed submission:

/*
    author:ujwalll
*/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const int INF = 1 << 29;
const int MOD = 1073741824;
#define pp pair<ll, ll>
#define ppi pair<int, int>
typedef long long int ll;
bool isPowerOfTwo(ll x) { return x && (!(x & (x - 1))); }
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
////////////////////////////////////////////////////////////////////
set<int> adj[200005];
bool vis[200005];
int cnt = 0;
int solve(int s) {
  vis[s] = 1;
  cnt++;
  for (auto i : adj[s]) {
    if (vis[i])
      continue;
    solve(i);
  }
}
int main() {
  int tc = 1;
  // cin>>tc;
  while (tc--) {
    memset(vis, 0, sizeof(vis));
    int n, m;
    cin >> n >> m;
    rep(i, m) {
      int x, y;
      cin >> x >> y;
      adj[x].insert(y);
      adj[y].insert(x);
    }
    int ans = 0;
    for1(i, n) {
      if (!vis[i]) {
        vis[i] = 1;
        solve(i);
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    cout << ans;
  }
  return 0;
}