Problem p03855 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(), a.end())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MP(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define INF LLONG_MAX / 2

using namespace std;
int MOD = 1000000007;
#define N 100
int par[2][N];
int rnk[2][N];

void init(int n, int num) {
  for (int i = 0; i < n; i++) {
    par[num][i] = i;
    rnk[num][i] = 0;
  }
}
int find(int x, int num) {
  if (par[num][x] == x)
    return x;
  else
    return par[num][x] = find(par[num][x], num);
}
void unite(int x, int y, int num) {
  x = find(x, num);
  y = find(y, num);
  if (x == y)
    return;

  if (rnk[num][x] < rnk[num][y])
    par[num][x] = y;
  else {
    par[num][y] = x;
    if (rnk[num][x] == rnk[num][y])
      rnk[num][x]++;
  }
}
bool same(int x, int y, int num) { return find(x, num) == find(y, num); }
signed main() {
  int n, k, l;
  cin >> n >> k >> l;
  map<pair<int, int>, int> m;
  vector<pair<int, int>> oya(n);
  init(n, 0);
  init(n, 1);
  rep(i, k) {
    int p, q;
    cin >> p >> q;
    unite(p - 1, q - 1, 0);
  }
  rep(i, l) {
    int p, q;
    cin >> p >> q;
    unite(p - 1, q - 1, 1);
  }
  rep(i, n) {
    oya[i] = MP(find(i, 0), find(i, 1));
    m[oya[i]]++;
  }
  rep(i, n) cout << m[oya[i]] << " ";
  cout << endl;

  return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl
// https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a rm -r -f
// test;oj dl http://arc065.contest.atcoder.jp/tasks/arc065_b

Fixed submission:
#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(), a.end())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MP(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define INF LLONG_MAX / 2

using namespace std;
int MOD = 1000000007;
#define N 200010
int par[2][N];
int rnk[2][N];

void init(int n, int num) {
  for (int i = 0; i < n; i++) {
    par[num][i] = i;
    rnk[num][i] = 0;
  }
}
int find(int x, int num) {
  if (par[num][x] == x)
    return x;
  else
    return par[num][x] = find(par[num][x], num);
}
void unite(int x, int y, int num) {
  x = find(x, num);
  y = find(y, num);
  if (x == y)
    return;

  if (rnk[num][x] < rnk[num][y])
    par[num][x] = y;
  else {
    par[num][y] = x;
    if (rnk[num][x] == rnk[num][y])
      rnk[num][x]++;
  }
}
bool same(int x, int y, int num) { return find(x, num) == find(y, num); }
signed main() {
  int n, k, l;
  cin >> n >> k >> l;
  map<pair<int, int>, int> m;
  vector<pair<int, int>> oya(n);
  init(n, 0);
  init(n, 1);
  rep(i, k) {
    int p, q;
    cin >> p >> q;
    unite(p - 1, q - 1, 0);
  }
  rep(i, l) {
    int p, q;
    cin >> p >> q;
    unite(p - 1, q - 1, 1);
  }
  rep(i, n) {
    oya[i] = MP(find(i, 0), find(i, 1));
    m[oya[i]]++;
  }
  rep(i, n) cout << m[oya[i]] << " ";
  cout << endl;

  return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl
// https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a rm -r -f
// test;oj dl http://arc065.contest.atcoder.jp/tasks/arc065_b