Problem p02536 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cstdio>
#include <tuple>
#define MAX 1000007
#define MP make_pair
#define ii long long
#define dd double
#define MAX_SIZE 1e7
#define mod 1000000007
#define gc getchar_unlocked
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define REP(i, b, n) for (long long i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(a) int((a).size())
#define forn(i, n)                                                             \
  for (int i = 0; i < int(n); ++i)                                             \
  ..> ||
#define w(x)                                                                   \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
#define inp(tmp)                                                               \
  ii tmp;                                                                      \
  cin >> tmp
#define DBG 0
#define print if (DBG)
using namespace std;
typedef pair<ii, ii> pii;
typedef pair<ll, ll> pl;
typedef vector<ii> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, vi> Node;

ii n, m;
vi par;
ii find_set(ii v) {
  if (v == par[v])
    return v;
  return find_set(par[v]);
}

void con(ii a, ii b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b)
    par[b] = a;
}
int main() {
  cin >> n >> m;
  par.pb(-1);
  REP(i, 1, n + 1) { par.pb(i); }

  rep(i, m) {
    inp(x);
    inp(y);
    con(x, y);
  }
  ii comp = 0;
  REP(i, 1, n + 1) {
    if (par[i] == i) {
      print cout << i << " is main ";
      comp++;
    }
  }
  cout << comp - 1;
  cin >> n;
}
/*
3 1
1 2

*/

Fixed submission:
#include <bits/stdc++.h>
#include <cstdio>
#include <tuple>
#define MAX 1000007
#define MP make_pair
#define ii long long
#define dd double
#define MAX_SIZE 1e7
#define mod 1000000007
#define gc getchar_unlocked
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define REP(i, b, n) for (long long i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(a) int((a).size())
#define forn(i, n)                                                             \
  for (int i = 0; i < int(n); ++i)                                             \
  ..> ||
#define w(x)                                                                   \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
#define inp(tmp)                                                               \
  ii tmp;                                                                      \
  cin >> tmp
#define DBG 0
#define print if (DBG)
using namespace std;
typedef pair<ii, ii> pii;
typedef pair<ll, ll> pl;
typedef vector<ii> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, vi> Node;

ii n, m;
vi par;
ii find_set(ii v) {
  if (v == par[v])
    return v;
  return par[v] = find_set(par[v]);
}

void con(ii a, ii b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b)
    par[b] = a;
}
int main() {
  cin >> n >> m;
  par.pb(-1);
  REP(i, 1, n + 1) { par.pb(i); }

  rep(i, m) {
    inp(x);
    inp(y);
    con(x, y);
  }
  ii comp = 0;
  REP(i, 1, n + 1) {
    if (par[i] == i) {
      print cout << i << " is main ";
      comp++;
    }
  }
  cout << comp - 1;
  cin >> n;
}
/*
3 1
1 2

*/