Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fst                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endk cout << "\n";
typedef long long int ll;
typedef long int l;
#define l(i, a, b) for (i = a; i < b; i++)
#define lo(i, a, b) for (i = a; i >= b; i--)
#define s(v) sort(v.begin(), v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test()                                                                 \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--) {                                                                \
    solve();                                                                   \
  };
#define test1()                                                                \
  int t = 1;                                                                   \
  while (t--) {                                                                \
    solve();                                                                   \
  };
bool isPrime(ll x) {
  ll i, n;
  n = sqrt(x);
  if (x == 1)
    return false;
  if (x == 2 || x == 3)
    return true;
  for (i = 2; i <= n; i++) {
    if (!(x % i))
      return false;
  }
  return true;
}
ll power(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y & 1)
      ans = ans * x;
    x = x * x;
    y = y >> 1;
  }
  return ans;
}
vll adj[100001];
vll visited(100001, 0);
ll sum = 0;
void dfs(ll n) {
  visited[n]++;
  sum++;
  ll i, j;
  j = adj[n].size();
  for (i = 0; i < j; i++) {
    // cout<<adj[n][i]<<"s "<<n;
    // endk
    if (!visited[adj[n][i]]) {
      dfs(adj[n][i]);
    }
  }
}
int solve() {
  ll n, m, i, ans = 0, j, k;
  cin >> n >> m;
  map<pair<ll, ll>, ll> cnt;
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    if (!cnt[{j, k}]) {
      cnt[{j, k}]++;
      adj[j].push_back(k);
      adj[k].push_back(j);
    }
  }
  ans = -1;
  for (i = 1; i <= n; i++) {
    if (!visited[i]) {
      sum = 0;
      dfs(i);
      ans = max(ans, sum);
    }
  }
  cout << ans;
  return 0;
}
int main() {
  fst;
  test1();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fst                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endk cout << "\n";
typedef long long int ll;
typedef long int l;
#define l(i, a, b) for (i = a; i < b; i++)
#define lo(i, a, b) for (i = a; i >= b; i--)
#define s(v) sort(v.begin(), v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test()                                                                 \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--) {                                                                \
    solve();                                                                   \
  };
#define test1()                                                                \
  int t = 1;                                                                   \
  while (t--) {                                                                \
    solve();                                                                   \
  };
bool isPrime(ll x) {
  ll i, n;
  n = sqrt(x);
  if (x == 1)
    return false;
  if (x == 2 || x == 3)
    return true;
  for (i = 2; i <= n; i++) {
    if (!(x % i))
      return false;
  }
  return true;
}
ll power(ll x, ll y) {
  ll ans = 1;
  while (y > 0) {
    if (y & 1)
      ans = ans * x;
    x = x * x;
    y = y >> 1;
  }
  return ans;
}
vector<vll> adj(200001);
map<ll, ll> visited;
ll sum = 0;
void dfs(ll n) {
  visited[n]++;
  sum++;
  ll i, j;
  j = adj[n].size();
  for (i = 0; i < j; i++) {
    // cout<<adj[n][i]<<"s "<<n;
    // endk
    if (!visited[adj[n][i]]) {
      dfs(adj[n][i]);
    }
  }
}
int solve() {
  ll n, m, i, ans = 0, j, k;
  cin >> n >> m;
  map<pair<ll, ll>, ll> cnt;
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    if (!cnt[{j, k}]) {
      cnt[{j, k}]++;
      adj[j].push_back(k);
      adj[k].push_back(j);
    }
  }
  ans = -1;
  for (i = 1; i <= n; i++) {
    if (!visited[i]) {
      sum = 0;
      dfs(i);
      ans = max(ans, sum);
    }
  }
  cout << ans;
  return 0;
}
int main() {
  fst;
  test1();
  return 0;
}