Language: C++

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

//num???v?????????????????¨???????????????.
int num_pos(std::vector<std::set<int> > v, int num) {
	for (size_t i = 0; i < v.size(); i++) {
		if (std::binary_search(v[i].begin(), v[i].end(), num)) {
			return i;
		}
	}
	std::cerr << "vector??????" << num << "??????????????????" << std::endl;
}


int main() {
	int n, query_num;

	std::cin >> n >> query_num;

	std::vector<std::set<int> > v(n);
	for (int i = 0; i < n; i++) {
		v[i].insert(i);
	}

	for (int i = 0; i < query_num; i++) {
		int query, a, b;
		std::cin >> query >> a >> b;
		if (query == 0) {//unite
			int c, d;
			c = num_pos(v, a);
			d = num_pos(v, b);
			if (c != d) {
				if (c > d)std::swap(c, d);
				std::copy(v[d].begin(), v[d].end(), v[c].end());
				v.erase(v.begin() + d);
			}
		} else {//same
			int pos = num_pos(v, a);
			if (std::find(v[pos].begin(), v[pos].end(), b) != v[pos].end()) {
				std::cout << 1 << std::endl;
			} else {
				std::cout << 0 << std::endl;
			}
		}
	}
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/string:51,
                 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/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'static _OI std::__copy_move<_IsMove, _IsSimple, _Category>::__copy_m(_II, _II, _OI) [with _II = std::_Rb_tree_const_iterator<int>; _OI = std::_Rb_tree_const_iterator<int>; bool _IsMove = false; bool _IsSimple = false; _Category = std::bidirectional_iterator_tag]':
/usr/include/c++/14/bits/stl_algobase.h:521:30:   required from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = _Rb_tree_const_iterator<int>; _OI = _Rb_tree_const_iterator<int>]'
  520 |       return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  521 |                               _Category>::__copy_m(__first, __last, __result);
      |                               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:548:42:   required from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = _Rb_tree_const_iterator<int>; _OI = _Rb_tree_const_iterator<int>]'
  548 |     { return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:556:31:   required from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = _Rb_tree_const_iterator<int>; _OI = _Rb_tree_const_iterator<int>]'
  556 |                 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  557 |                                              std::__niter_base(__last),
      |                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~
  558 |                                              std::__niter_base(__result)));
      |                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:651:7:   required from '_OI std::copy(_II, _II, _OI) [with _II = _Rb_tree_const_iterator<int>; _OI = _Rb_tree_const_iterator<int>]'
  650 |       return std::__copy_move_a<__is_move_iterator<_II>::__value>
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  651 |              (std::__miter_base(__first), std::__miter_base(__last), __result);
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:36:14:   required from here
   36 |                                 std::copy(v[d].begin(), v[d].end(), v[c].end());
      |                                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:371:23: error: assignment of read-only location '__result.std::_Rb_tree_const_iterator<int>::operator*()'
  371 |             *__result = *__first;
      |             ~~~~~~~~~~^~~~~~~~~~
a.cc: In function 'int num_pos(std::vector<std::set<int> >, int)':
a.cc:13:76: warning: control reaches end of non-void function [-Wreturn-type]
   13 |         std::cerr << "vector??????" << num << "??????????????????" << std::endl;
      |                                                                            ^~~~