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

#include <bits/stdc++.h>

using namespace std;
#define PI 3.1415926536

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define REP(i, n) for (i = 0; i < n; i++)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void solve() {
  double n;
  cin >> n;

  if (n > 0 && n < 4)
    cout << "N\\n";
  else {
    double ans = n * n - 4 * n;
    double res = sqrt(ans);

    double a = (n + res) / 2;
    double b = (n - res) / 2;

    cout << "Y"
         << " ";
    cout << setprecision(11);
    cout << a << " " << b << endl;
  }
}

int vis[2000005];
int n, m;
vi graph[2000005];
int res = 0;
void dfs(int i) {
  vis[i] = 1;
  res++;
  for (auto &it : graph[i]) {
    if (!vis[it])
      dfs(it);
  }
}
int32_t main() {

  cin >> n >> m;

  int i;

  for (i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    graph[x].pb(y);
    graph[y].pb(x);
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    if (!vis[i]) {
      res = 0;
      dfs(i);
      ans = max(ans, res);
    }
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define PI 3.1415926536

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define REP(i, n) for (i = 0; i < n; i++)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void solve() {
  double n;
  cin >> n;

  if (n > 0 && n < 4)
    cout << "N\\n";
  else {
    double ans = n * n - 4 * n;
    double res = sqrt(ans);

    double a = (n + res) / 2;
    double b = (n - res) / 2;

    cout << "Y"
         << " ";
    cout << setprecision(11);
    cout << a << " " << b << endl;
  }
}

int vis[1000001];
int n, m;
vi graph[10000 + 1];
int res = 0;
void dfs(int i) {
  vis[i] = 1;
  res++;
  for (auto &it : graph[i]) {
    if (!vis[it])
      dfs(it);
  }
}
int32_t main() {
  // c_p_c();
  FIO;

  cin >> n >> m;

  int i;

  for (i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    graph[x].pb(y);
    graph[y].pb(x);
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    if (!vis[i]) {
      res = 0;
      dfs(i);
      ans = max(ans, res);
    }
  }
  cout << ans;
}