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

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

#define ll long long int
#define inv(name, Type, size)                                                  \\
  vector<Type> name(size);                                                     \\
  for (int index = 0; index < size; index++)                                   \\
    cin >> name[index];
#define F(a, n, i) for (int i = a; i < n; i++)
#define FLL(a, n, i) for (long long int i = a; i < n; i++)
#define pb push_back
#define endl "\\n"
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

const int mod = 1000000007;
const int modpro = 988244353;

const int di[8] = {-1, 0, 1, 0, -1, 1, 1, -1},
          dj[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<bool> visi;
vector<vector<int>> adj;

int dfs(int i) {
  stack<int> s;
  s.push(i);
  int nodes = 0;
  visi[i] = true;
  while (!(s.empty())) {
    int temp;
    temp = s.top();
    nodes++;
    s.pop();
    for (int adjNode : adj[temp]) {
      if (visi[adjNode] == false) {
        s.push(adjNode);
        visi[adjNode] = true;
      }
    }
  }
  return nodes;
}

void solve() {
  int n, m;
  cin >> n >> m;
  visi.resize(n);
  adj.resize(n);
  F(0, m, i) {
    int u, v;
    cin >> u >> v;
    adj[u - 1].pb(v - 1);
    adj[v - 1].pb(u - 1);
  }
  int ma = 0;
  F(0, n, i) {
    if (visi[i] == false)
      ma = max(ma, dfs(i));
  }
  cout << ma;
}

int main() {

  // freopen("out", "w", stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();

  cerr << endl << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << " ms\\n";
}


Error: WA

Fixed submission:

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

#define ll long long int
#define inv(name, Type, size)                                                  \\
  vector<Type> name(size);                                                     \\
  for (int index = 0; index < size; index++)                                   \\
    cin >> name[index];
#define F(a, n, i) for (int i = a; i < n; i++)
#define FLL(a, n, i) for (long long int i = a; i < n; i++)
#define pb push_back
#define endl "\\n"
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

const int mod = 1000000007;
const int modpro = 988244353;

const int di[8] = {-1, 0, 1, 0, -1, 1, 1, -1},
          dj[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int n, m;
vector<vector<int>> adj;
bool visi[100001];
int dfs(int i) {
  // cout<<"hi"<<":";
  map<int, int> hm;
  int edges = 0;
  stack<int> st;
  st.push(i);
  int temp;
  while (!st.empty()) {
    // cout<<"hi"<<endl;
    temp = st.top();
    // cout<<temp<<" ";

    st.pop();
    if (hm[temp] > 0)
      continue;
    hm[temp]++;
    edges++;
    visi[temp] = true;
    for (int adjnode : adj[temp]) {
      if (visi[adjnode] == false)
        st.push(adjnode);
    }
  }
  // cout<<endl;
  return edges;
}

void solve() {
  cin >> n >> m;
  memset(visi, false, sizeof(visi));
  adj.resize(n);
  vector<pair<int, int>> tempad(m);
  F(0, m, i) {
    int u, v;
    cin >> u >> v;
    tempad[i].first = min(u, v);
    tempad[i].second = max(u, v);
  }
  sort(all(tempad), [](auto &a, auto &b) {
    if (a.first == b.first)
      return a.second < b.second;
    return a.second < b.second;
  });
  adj[tempad[0].first - 1].pb(tempad[0].second - 1);
  adj[tempad[0].second - 1].pb(tempad[0].first - 1);
  F(1, m, i) {
    if (tempad[i].first == tempad[i - 1].first &&
        tempad[i].second == tempad[i - 1].second) {
      // cout<<tempad[i].first<<" "<<tempad[i].second<<endl;
    } else {
      adj[tempad[i].first - 1].pb(tempad[i].second - 1);
      adj[tempad[i].second - 1].pb(tempad[i].first - 1);
    }
  }
  vector<int> ed;
  F(0, n, i) {
    if (visi[i] == false) {
      ed.pb(dfs(i));
    }
  }
  sort(all(ed));
  // for(int ned:ed) cout<<ned<<" ";
  // cout<<endl;
  cout << *max_element(all(ed));
}

int main() {

  // freopen("out", "w", stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();

  cerr << endl << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << " ms\\n";
}