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

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t)                                                                   \\
  cin >> t;                                                                    \\
  while (t--)
#define bitcount __builtin_popcount
#define endl "\\n"
#define sz(s) (int)s.size()
#define mem(n, m) memset(n, m, sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ren(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (ll i = a; i <= b; i++)
#define ffo(i, a, b) for (ll i = a; i >= b; i--)
#define ffi(i, a, b, c) for (ll i = a; i <= b; i += c)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
const int mod = 1000000007;

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

vector<ll> g[200005];
bool vis[200005];
ll c = 1;

void dfs(ll s) {
  vis[s] = true;
  for (auto it : g[s]) {
    if (!vis[it])
      c++, dfs(it);
  }
}

void solve() {
  ll n, m, u, v, ans = 0;
  cin >> n >> m;
  rep(i, m) {
    cin >> u >> v;
    g[u].pb(v), g[v].pb(u);
  }
  fo(i, 1, n) {
    if (!vis[i])
      c = 1, dfs(i), ans = max(ans, c);
  }
  cout << ans << endl;
}

int main() {
  IOS;
  // io_set();
  ll tt = 1;
  // cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t)                                                                   \\
  cin >> t;                                                                    \\
  while (t--)
#define bitcount __builtin_popcount
#define endl "\\n"
#define sz(s) (int)s.size()
#define mem(n, m) memset(n, m, sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ren(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (ll i = a; i <= b; i++)
#define ffo(i, a, b) for (ll i = a; i >= b; i--)
#define ffi(i, a, b, c) for (ll i = a; i <= b; i += c)
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
const int mod = 1000000007;

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

vector<ll> g[100005];
bool vis[100005];
ll c = 1;

void dfs(ll s) {
  vis[s] = true;
  for (auto it : g[s]) {
    if (!vis[it])
      c++, dfs(it);
  }
}

void solve() {
  ll n, m, u, v, ans = 0;
  cin >> n >> m;
  rep(i, m) {
    cin >> u >> v;
    g[u].pb(v), g[v].pb(u);
  }
  fo(i, 1, n) {
    if (!vis[i])
      c = 1, dfs(i), ans = max(ans, c);
  }
  cout << ans << endl;
}

int main() {
  IOS;
  // io_set();
  ll tt = 1;
  // cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}