Language: C++

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

const int nmax = 2 * 100005;
typedef pair<int, int> P;
map<P, int> MAP;
int N, K, L;

// union - find tree !!!!!!!!!!!!!!!!!!!!!!!!!
vector<int> par[2]; //oya
vector<int> rnk[2]; //ki no hu ka sa
// n要素で初期化
void init(int n){
    FOR(i,0,2){
      par[i].resize(n);rnk[i].resize(n);
      FOR(j, 0, n){par[i][j] = j;rnk[i][j] = 0;}
    }
}
//木の根を求める
int find(int i, int x){
    if(par[0][x] == x) return x;
    else return par[0][x] = find(par[0][x]);
}
//xとyの属する集合を併合
void unite(int i, int x, int y){
    x = find(x);y = find(y);
    if(x == y) return;
    if(rnk[i][x] < rnk[i][y]) par[i][x] = y;
    else{par[i][y] = x;if(rnk[i][x] == rnk[i][y]) rnk[i][x]++;}
    return;
}
bool isSame(int x, int y){return find(x) == find(y);}

int main(){
  cin >> N >> K >> L;
  init(N);
  // 道路で同じ組みかどうか
  FOR(i,0,N) visit[i] = false;
  FOR(i,0,K){
    int a, b;
    cin >> a >> b;
    a--;b--;
    unite(0,a,b);
  }
  // 鉄道で同じかどうか
  FOR(i,0,N) visit[i] = false;
  FOR(i,0,L){
    int a, b;
    cin >> a >> b;
    a--;b--;
    unite(1,a,b);
  }
  FOR (i,0,N) MAP[P(find(0,par[0][i]),find(1,par[1][i]))]++;
  FOR(i,0,N){
    printf("%d%c", MAP[P(find(0,par[0][i]),find(1,par[1][i]))], i == N - 1 ? '\n' : ' ');
  }
  return 0;
}


Compiler output:
a.cc: In function 'int find(int, int)':
a.cc:37:33: error: no matching function for call to 'find(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   37 |     else return par[0][x] = find(par[0][x]);
      |                             ~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc:35:5: note: candidate: 'int find(int, int)'
   35 | int find(int i, int x){
      |     ^~~~
a.cc:35:5: note:   candidate expects 2 arguments, 1 provided
a.cc: In function 'void unite(int, int, int)':
a.cc:41:13: error: no matching function for call to 'find(int&)'
   41 |     x = find(x);y = find(y);
      |         ~~~~^~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc:35:5: note: candidate: 'int find(int, int)'
   35 | int find(int i, int x){
      |     ^~~~
a.cc:35:5: note:   candidate expects 2 arguments, 1 provided
a.cc:41:25: error: no matching function for call to 'find(int&)'
   41 |     x = find(x);y = find(y);
      |                     ~~~~^~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc:35:5: note: candidate: 'int find(int, int)'
   35 | int find(int i, int x){
      |     ^~~~
a.cc:35:5: note:   candidate expects 2 arguments, 1 provided
a.cc: In function 'bool isSame(int, int)':
a.cc:47:38: error: no matching function for call to 'find(int&)'
   47 | bool isSame(int x, int y){return find(x) == find(y);}
      |                                  ~~~~^~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc:35:5: note: candidate: 'int find(int, int)'
   35 | int find(int i, int x){
      |     ^~~~
a.cc:35:5: note:   candidate expects 2 arguments, 1 provided
a.cc:47:49: error: no matching function for call to 'find(int&)'
   47 | bool isSame(int x, int y){return find(x) == find(y);}
      |                                             ~~~~^~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc:35:5: note: candidate: 'int find(int, int)'
   35 | int find(int i, int x){
      |     ^~~~
a.cc:35:5: note:   candidate expects 2 arguments, 1 provided
a.cc: In function 'int main()':
a.cc:53:14: error: 'visit' was not declared in this scope
   53 |   FOR(i,0,N) visit[i] = false;
      |              ^~~~~
a.cc:15:1: note: 'std::visit' is defined in header '<variant>'; this is probably fixable by adding '#include <variant>'
   14 | #include <bitset>
  +++ |+#include <variant>
   15 | using namespace std;
a.cc:61:14: error: 'visit' was not declared in this scope
   61 |   FOR(i,0,N) visit[i] = false;
      |              ^~~~~
a.cc:61:14: note: 'std::visit' is defined in header '<variant>'; this is probably fixable by adding '#include <variant>'