Problem p02573 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;*/

#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout << val << ch

typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
int find(vector<int> &par, int a) {
  if (par[a] == a) {
    return a;
  }
  return find(par, par[a]);
}
/*********************************************************************/
void test(int r) {
  int n, m;
  cin >> n >> m;
  vector<int> par(n + 1, 0), cn(n + 1, 0);
  int i, j;
  for (i = 1; i <= n; i++) {
    par[i] = i;
    cn[i] = 1;
  }
  for (i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    int p1, p2;
    p1 = find(par, a);
    p2 = find(par, b);
    if (p1 != p2) {
      par[p1] = p2;
      cn[p2] += cn[p1];
    }
  }
  int mx = 0;
  for (i = 1; i <= n; i++)
    mx = max(mx, cn[i]);
  cout << mx << endl;
}
/***********************************************************************/
int main() {
  fast();
  int t = 1, r;
  // cin>>t;
  for (r = 1; r <= t; r++)
    test(r);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;*/

#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout << val << ch

typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
int find(vector<int> &par, int a) {
  if (par[a] == a) {
    return a;
  }
  par[a] = find(par, par[a]);
  return par[a];
}
/*********************************************************************/
void test(int r) {
  int n, m;
  cin >> n >> m;
  vector<int> par(n + 1, 0), cn(n + 1, 0);
  int i, j;
  for (i = 1; i <= n; i++) {
    par[i] = i;
    cn[i] = 1;
  }
  for (i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    int p1, p2;
    p1 = find(par, a);
    p2 = find(par, b);
    if (p1 != p2) {
      par[p1] = p2;
      cn[p2] += cn[p1];
    }
  }
  int mx = 0;
  for (i = 1; i <= n; i++)
    mx = max(mx, cn[i]);
  cout << mx << endl;
}
/***********************************************************************/
int main() {
  fast();
  int t = 1, r;
  // cin>>t;
  for (r = 1; r <= t; r++)
    test(r);
  return 0;
}