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

#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repc(i, a, b, c)                                                       \\
  for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r)                                                              \\
  (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) : 0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\\n'
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/
// ll power(ll x, ll y) {
//     ll res = 1;x %= mod;
//     while (y > 0) {
//         if (y & 1)res = (res*x) % mod;
//         y = y>>1;
//         x = (x*x) % mod;
//     }
//     return res%mod;
// }
// bool cmp(pair<int, int> a, pair<int, int> b){
//     return (a.fi+a.si) > (b.fi+b.si);
// }
// void solve(){
//     int n, s = 0;
//     cin >> n;
//     vector<pair<int, int> > v(n) ;
//     rep(i, 0, n)cin >> v[i].fi >> v[i].si, s += v[i].fi;
//     sort(all(v), cmp);
//     rep(i, 0, n){
//         if(v[i].fi+v[i].si <= s){
//             cout << "INDEFINITELY\\n";
//             return;
//         }
//         else s -= v[i].fi;
//     }
//     int mi, ans = s;
//     rep(i,0,n){
//         if()
//     }
// }
class Dsu {
public:
  vector<int> drr;
  vector<int> size_arr;
  Dsu(int n) { rep(i, 0, n + 1) drr.pb(i), size_arr.pb(1); }
  int f_p(int a) { return drr[a] == a ? a : f_p(drr[a]); }
  ll size(int a) { return (ll)size_arr[f_p(a)]; }
  void uni(int a, int b) {
    int ap = f_p(a);
    int bp = f_p(b);
    if (ap == bp)
      return;
    if (size_arr[ap] <= size_arr[bp])
      swap(ap, bp);
    drr[bp] = ap;
    size_arr[ap] += size_arr[bp];
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  Dsu d(n + 5);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    d.uni(a, b);
  }
  int ans = 0;
  rep(i, 1, n + 1) { ans = max(ans, d.size(i)); }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // fact((2e6+10));
  // //declare  and  global
  int t = 1;
  // cin >> t;
  rep(i, 0, t) { solve(); }
}


Error: 0

Fixed submission:

#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repc(i, a, b, c)                                                       \\
  for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r)                                                              \\
  (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) : 0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\\n'
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/
// ll power(ll x, ll y) {
//     ll res = 1;x %= mod;
//     while (y > 0) {
//         if (y & 1)res = (res*x) % mod;
//         y = y>>1;
//         x = (x*x) % mod;
//     }
//     return res%mod;
// }
const int faxsize = 1e6 + 5;
vector<int> fax[faxsize];
// bool cmp(pair<int, int> a, pair<int, int> b){
//     return (a.fi+a.si) > (b.fi+b.si);
// }
// void solve(){
//     int n, s = 0;
//     cin >> n;
//     vector<pair<int, int> > v(n) ;
//     rep(i, 0, n)cin >> v[i].fi >> v[i].si, s += v[i].fi;
//     sort(all(v), cmp);
//     rep(i, 0, n){
//         if(v[i].fi+v[i].si <= s){
//             cout << "INDEFINITELY\\n";
//             return;
//         }
//         else s -= v[i].fi;
//     }
//     int mi, ans = s;
//     rep(i,0,n){
//         if()
//     }
// }
class Dsu {
public:
  vector<int> drr;
  vector<int> size_arr;
  Dsu(int n) { rep(i, 0, n + 1) drr.pb(i), size_arr.pb(1); }
  int f_p(int a) { return drr[a] == a ? a : f_p(drr[a]); }
  ll size(int a) { return (ll)size_arr[f_p(a)]; }
  void uni(int a, int b) {
    int ap = f_p(a);
    int bp = f_p(b);
    if (ap == bp)
      return;
    if (size_arr[ap] <= size_arr[bp])
      swap(ap, bp);
    drr[bp] = ap;
    size_arr[ap] += size_arr[bp];
  }
};
void solve() {
  int n, m;
  cin >> n >> m;
  Dsu d(n + 5);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    d.uni(a, b);
  }
  int ans = 0;
  rep(i, 1, n + 1) { ans = max(ans, d.size(i)); }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // fact((2e6+10));
  // //declare  and  global
  rep(i, 2, faxsize) if (fax[i].size() == 0) repc(j, i, faxsize + 1, i) fax[j]
      .push_back(i);
  int t = 1;
  // cin >> t;
  rep(i, 0, t) { solve(); }
}