Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long int
#define f(i, x, n) for (int i = x; i < n; i++)
#define FASTIO                                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
  }
template <typename T> inline T gcd(T a, T b) {
  while (b != 0)
    swap(b, a %= b);
  return a;
}

template <typename T> inline void seethis(vector<T> vect) {
  for (T x : vect)
    cout << x << " ";
  cout << "\\n";
}

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
// LCM
int lcm(int a, int b) { return a * (b / gcd(a, b)); }

// For sort by second
bool cmp(const pair<int, int> &a) { return a.first < a.second; }

const int MAXN = 200000 + 5;
vector<ll> adj[MAXN];
vector<bool> visited(MAXN, false);

ll n, m;

ll dfs(int par) {
  visited[par] = true;
  ll res = 1;
  for (int child : adj[par]) {
    if (!visited[child])
      res += dfs(child);
  }
  return res;
}

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

  cin >> n >> m;
  set<pair<int, int>> se;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (se.find({u, v}) == se.end() and se.find({v, u}) == se.end()) {
      adj[u - 1].push_back(v - 1);
      adj[v - 1].push_back(u - 1);
      se.insert({u, v});
    }
  }

  ll ans = -inf;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      ll x = dfs(i);
      ans = max(ans, x);
    }
  }
  cout << ans << "\\n";

  return 0;
}

Error: WA

Fixed submission:

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

#define ll long long int
#define f(i, x, n) for (int i = x; i < n; i++)
#define FASTIO                                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
  }
template <typename T> inline T gcd(T a, T b) {
  while (b != 0)
    swap(b, a %= b);
  return a;
}

template <typename T> inline void seethis(vector<T> vect) {
  for (T x : vect)
    cout << x << " ";
  cout << "\\n";
}

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
// LCM
int lcm(int a, int b) { return a * (b / gcd(a, b)); }

// For sort by second
bool cmp(const pair<int, int> &a) { return a.first < a.second; }

const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];
vector<bool> visited(MAXN, false);
vector<ll> dist(MAXN, 0);
ll n, m;

int dfs(int par) {
  visited[par] = true;
  int res = 1;
  for (int child : adj[par]) {
    if (!visited[child])
      res += dfs(child);
  }
  return res;

  return dist[par];
}

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

  cin >> n >> m;
  set<pair<int, int>> se;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (se.find({u, v}) == se.end() and se.find({v, u}) == se.end()) {
      adj[u - 1].push_back(v - 1);
      adj[v - 1].push_back(u - 1);
      se.insert({u, v});
    }
  }

  int ans = INT_MIN;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      int x = dfs(i);
      ans = max(ans, x);
    }
  }
  cout << ans << "\\n";

  return 0;
}