Problem p02573 (C++)

Buggy submission (status: Runtime Error):
// R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>

using namespace std;

vector<int> adj[100005];
bool vis[100005];
int cnt;
void dfs(int node) {
  vis[node] = true;
  cnt++;
  for (int i = 0; i < adj[node].size(); ++i) {
    if (!vis[adj[node][i]])
      dfs(adj[node][i]);
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  memset(vis, false, sizeof vis);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  int maxm = 0;
  repA(i, 1, n) {
    cnt = 0;
    if (!vis[i])
      dfs(i);
    maxm = max(maxm, cnt);
  }
  cout << maxm;
}

signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }

  return 0;
}


Fixed submission:
// R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>

using namespace std;

vector<int> adj[200005];
bool vis[200005];
int cnt;
void dfs(int node) {
  vis[node] = true;
  cnt++;
  for (int i = 0; i < adj[node].size(); ++i) {
    if (!vis[adj[node][i]])
      dfs(adj[node][i]);
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  memset(vis, false, sizeof vis);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  int maxm = 0;
  repA(i, 1, n) {
    cnt = 0;
    if (!vis[i])
      dfs(i);
    maxm = max(maxm, cnt);
  }
  cout << maxm;
}

signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }

  return 0;
}