Language: C++

#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// Manages Union-Find Forest.
class UnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;

 public:
  // Initialize forest.
  // parent_[i]=i, rank_[i]=0, size_[i]=1.
  UnionFindForest(const int &n);
  // Get the number of the root of the node q.
  int Root(const int &q);
  // Return true if the roots of x and y is same.
  bool IsSame(const int &x, const int &y);
  // Unite the tree x and tree y.
  void Unite(int x, int y);
  // Get the number of nodes which are the same group as node q.
  int Size(const int &q);
};
UnionFindForest::UnionFindForest(const int &n) {
  parent_.resize(n);
  rank_.resize(n);
  size_.resize(n);
  for (int i = 0; i < n; i++) {
    parent_[i] = i;
    rank_[i]   = 0;
    size_[i]   = 1;
  }
}
int UnionFindForest::Size(const int &q) {
  return size_[Root(q)];
}

int UnionFindForest::Root(const int &q) {
  if (parent_[q] == q) {
    return q;
  } else {
    return parent_[q] = Root(parent_[q]);
  }
}

bool UnionFindForest::IsSame(const int &x, const int &y) {
  return Root(x) == Root(y);
}

void UnionFindForest::Unite(int x, int y) {
  x = Root(x);
  y = Root(y);
  if (x == y) return;
  if (rank_[x] < rank_[y]) {
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
}

struct Node {
  int root_road;
  int root_rail;
  const bool operator==(const Node &a) {
    if (root_rail == a.root_rail && root_road == a.root_road) {
      return true;
    } else {
      return false;
    }
  }
  const bool operator<(const Node &a) {
    if (root_road == a.root_road) {
      return root_rail < a.root_rail;
    } else {
      return root_road < a.root_road;
    }
  }
  const bool operator>(const Node &a) {
    if (root_road == a.root_road) {
      return root_rail > a.root_rail;
    } else {
      return root_road > a.root_road;
    }
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n, k, l;
  cin >> n >> k >> l;
  std::unordered_set<int> road_connection[200001], rail_connection[200001];
  for (int i = 0; i < k; i++) {
    int p, q;
    cin >> p >> q;
    road_connection[p].insert(q);
    road_connection[q].insert(p);
  }
  for (int i = 0; i < l; i++) {
    int p, q;
    cin >> p >> q;
    rail_connection[p].insert(q);
    rail_connection[q].insert(p);
  }

  UnionFindForest uf_road(n + 1);
  for (int i = 1; i <= n; i++) {
    for (auto x : road_connection[i]) {
      uf_road.Unite(i, x);
    }
  }
  UnionFindForest uf_rail(n + 1);

  for (int i = 1; i <= n; i++) {
    for (auto x : rail_connection[i]) {
      uf_rail.Unite(i, x);
    }
  }
  std::unordered_multiset<Node> set;
  for (int i = 1; i <= n; i++) {
    Node node;
    node.root_rail = uf_rail.Root(i);
    node.root_road = uf_road.Root(i);
    set.insert(node);
  }

  for (int i = 1; i <= n; i++) {
    Node node;
    node.root_rail = uf_rail.Root(i);
    node.root_road = uf_road.Root(i);
    cout << set.count(node) << " ";
  }

  cout << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:139:33: error: use of deleted function 'std::unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset() [with _Value = Node; _Hash = std::hash<Node>; _Pred = std::equal_to<Node>; _Alloc = std::allocator<Node>]'
  139 |   std::unordered_multiset<Node> set;
      |                                 ^~~
In file included from /usr/include/c++/14/unordered_set:41,
                 from a.cc:9:
/usr/include/c++/14/bits/unordered_set.h:1009:7: note: 'std::unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset() [with _Value = Node; _Hash = std::hash<Node>; _Pred = std::equal_to<Node>; _Alloc = std::allocator<Node>]' is implicitly deleted because the default definition would be ill-formed:
 1009 |       unordered_multiset() = default;
      |       ^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/unordered_set.h: At global scope:
/usr/include/c++/14/bits/unordered_set.h:1009:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = Node; _Value = Node; _Alloc = std::allocator<Node>; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<Node>; _Hash = std::hash<Node>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, true, false>]'
In file included from /usr/include/c++/14/bits/unordered_set.h:33:
/usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = Node; _Value = Node; _Alloc = std::allocator<Node>; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<Node>; _Hash = std::hash<Node>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, true, false>]' is implicitly deleted because the default definition would be ill-formed:
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = Node; _Value = Node; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<Node>; _Hash = std::hash<Node>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, true, false>]'
In file included from /usr/include/c++/14/bits/hashtable.h:35:
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = Node; _Value = Node; _ExtractKey = std::__detail::_Identity; _Equal = std::equal_to<Node>; _Hash = std::hash<Node>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, true, false>]' is implicitly deleted because the default definition would be ill-formed:
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = Node; _Value = Node; _ExtractKey = std::__detail::_Identity; _Hash = std::hash<Node>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]'
/usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<Node>]':
/usr/include/c++/14/bits/hashtable_policy.h:1328:7:   required from here
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<Node>::hash()'
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/iomanip:42,
                 from a.cc:4:
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<Node>::hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<Node, false>::__hash_enum()'
/usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = Node; bool <anonymous> = false]'
   83 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/usr/include/c++/14/bits/functional_hash.h:83:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = Node; bool <anonymous> = false]' is private within this context
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1245 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = Node; _Value = Node; _ExtractKey = std::__detail::_Identity; _Hash = std::hash<Node>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed:
 1328 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<Node>, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<Node>, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed:
 1242 |     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<Node>::~hash()'
/usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<Node>::~hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = Node; bool <anonymous> = false]' is private within this context
/usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: use '-fdiagnostics-all-candidates' to display considered candidates
 1731 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<Node, Node, std::__detail::_Identity, std::hash<Node>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()'
/usr/include/c++/14/bits/hashtable_policy.h:1306:12: note: 'std::__detail::_Hash_code_base<Node, Node, std::__detail::_Identity, std::hash<Node>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()' is implicitly deleted because the default definition would be ill-formed:
 1306 |     struct _Hash_code_base
      |            ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1306:12: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<Node>, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/14/bits/hashtable.h:539:7: note: use '-fdiagnostics-all-candidates' to display considered candidates
  539 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<Node, Node, std::__detail::_Identity, std::equal_to<Node>, std::hash<Node>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, true, false> >::~_Hashtable_base()'
/usr/include/c++/14/bits/hashtable_policy.h:1688:12: note: 'std::__detail::_Hashtable_base<Node, Node, std::__detail::_Identity, std::equal_to<Node>, std::hash<Node>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, true, false> >::~_Hashtable_base()' is implicitly deleted because the default definition would be ill-formed:
 1688 |     struct _Hashtable_base
      |            ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/hashtable_policy.h:1688:12: error: use of deleted function 'std::__detail::_Hash_code_base<Node, Node, std::__detail::_Identity, std::hash<Node>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()'
/usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'constexpr std::_En