Language: C++

#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

// Union-Find木
template <typename T>
struct UnionFind {
  int n;
  // vector<T> par;
  vector<T> rank;

 public:
  explicit UnionFind(int n) {
    this->n = n;
    par = vector<T>(n, 0);
    iota(par.begin(), par.end(), 0);
    rank = vector<T>(n, 0);
  }
  // 木の根を求める
  T root(T x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  // x と y が同じ集合に属するか調べる
  bool same(T x, T y) {
    return root(x) == root(y);
  }
  // x と y が属する集合を併合する
  void unite(T x, T y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  // 連結成分の数を数える
  int groups() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      // グループには根が自分と同じものが一つずつある
      if (par[i] == i) ans++;
    }
    return ans;
  }
};

// カウンター
template <typename T>
struct Counter {
  map<T, ull> cnt;
  void add(T key) {
    if (cnt.count(key)) {
      cnt[key]++;
    } else {
      cnt[key] = 1;
    }
  }
  void add(vector<T> keys) {
    for (auto key : keys) {
      add(key);
    }
  }
  ll get(T key) {
    if (cnt.count(key)) {
      return cnt[key];
    } else {
      return 0;
    }
  }
  pair<T, ull> max() {
    T key;
    ull mx = 0;
    for (auto kv : cnt) {
      if (kv.second > mx) {
        mx = kv.second;
        key = kv.first;
      }
    }
    return make_pair(key, mx);
  }
  typename map<T, ll>::iterator begin() {
    return cnt.begin();
  }
  typename map<T, ll>::iterator end() {
    return cnt.end();
  }
  typename map<T, ll>::reverse_iterator rbegin() {
    return cnt.rbegin();
  }
  typename map<T, ll>::reverse_iterator rend() {
    return cnt.rend();
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K, L;
  cin >> N >> K >> L;

  UnionFind<int> road(N);
  UnionFind<int> rail(N);

  REP(i, K) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    road.unite(p, q);
  }
  REP(i, L) {
    int r, s;
    cin >> r >> s;
    r--;
    s--;
    rail.unite(r, s);
  }

  Counter<pair<int, int>> c;
  REP(i, N) {
    c.add(make_pair(road.root(i), rail.root(i)));
  }
  REP(i, N) {
    cout << c.get(make_pair(road.root(i), rail.root(i)));
    if (i < N - 1) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}


Compiler output:
a.cc: In constructor 'UnionFind<T>::UnionFind(int)':
a.cc:39:5: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   39 |     par = vector<T>(n, 0);
      |     ^~~
      |     __pstl::execution::v1::par
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/14/algorithm:86,
                 from a.cc:7:
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In member function 'T UnionFind<T>::root(T)':
a.cc:45:9: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   45 |     if (par[x] == x) {
      |         ^~~
      |         __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In member function 'void UnionFind<T>::unite(T, T)':
a.cc:61:7: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   61 |       par[x] = y;
      |       ^~~
      |       __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc:63:7: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   63 |       par[y] = x;
      |       ^~~
      |       __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In member function 'int UnionFind<T>::groups()':
a.cc:72:11: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   72 |       if (par[i] == i) ans++;
      |           ^~~
      |           __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~