Language: C++

#include <bits/stdc++.h>
using namespace std;

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define rep1(a, b, c)  for(int a = (b); a < (c); ++a)
#define each(a, b)     for(auto& a : b)

#define sz(x)       (int)(x).size()
#define all(a)      (a).begin(),(a).end()

#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cout << #x << " = " << x << endl;
#define vt vector
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bitcnt(x) __builtin_popcount(x)

using ll = long long;

const int inf = (int)1e9 + 5;
const ll infl = (ll)1e18 + 5;
const int mod = 1e9 + 7;
const int nax = 1e5 + 10;
int link[nax], size[nax];

int find(int x){
	if(link[x] == x) return x;
	return link[x] = find(link[x]);
}

void join(int a, int b){
	a = find(a);
	b = find(b);
	if(size[a] < size[b]) swap(a, b);
	size[a] += size[b];
	link[b] = a;
}



void solve(){
	int n, m; cin >> n >> m;
	rep1(i, 1, n+1) link[i] = i, size[i] = 1;
	rep(i, m){
		int u, v;
		cin >> u >> v;
		join(u, v);
	}
	set<int> s;
	rep1(i, 1, n+1){
		s.insert(find(i));
	}
	int ans = sz(s); ans -= 1;
	cout << ans << '\n';
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Compiler output:
a.cc:30:13: error: 'int link [100010]' redeclared as different kind of entity
   30 | int link[nax], size[nax];
      |             ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:819:12: note: previous declaration 'int link(const char*, const char*)'
  819 | extern int link (const char *__from, const char *__to)
      |            ^~~~
a.cc: In function 'int find(int)':
a.cc:33:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |         if(link[x] == x) return x;
      |                  ^
a.cc:33:20: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   33 |         if(link[x] == x) return x;
      |            ~~~~~~~~^~~~
a.cc:34:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   34 |         return link[x] = find(link[x]);
      |                      ^
a.cc:34:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   34 |         return link[x] = find(link[x]);
      |                                     ^
a.cc:34:30: error: no matching function for call to 'find(int (&)(const char*, const char*) noexcept)'
   34 |         return link[x] = find(link[x]);
      |                          ~~~~^~~~~~~~~
a.cc:32:5: note: candidate: 'int find(int)' (near match)
   32 | int find(int x){
      |     ^~~~
a.cc:32:5: note:   conversion of argument 1 would be ill-formed:
a.cc:34:37: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   34 |         return link[x] = find(link[x]);
      |                               ~~~~~~^
      |                                     |
      |                                     int (*)(const char*, const char*) noexcept
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/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/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/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: In function 'void join(int, int)':
a.cc:40:12: error: reference to 'size' is ambiguous
   40 |         if(size[a] < size[b]) swap(a, b);
      |            ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:30:16: note:                 'int size [100010]'
   30 | int link[nax], size[nax];
      |                ^~~~
a.cc:40:22: error: reference to 'size' is ambiguous
   40 |         if(size[a] < size[b]) swap(a, b);
      |                      ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:30:16: note:                 'int size [100010]'
   30 | int link[nax], size[nax];
      |                ^~~~
a.cc:41:9: error: reference to 'size' is ambiguous
   41 |         size[a] += size[b];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:30:16: note:                 'int size [100010]'
   30 | int link[nax], size[nax];
      |                ^~~~
a.cc:41:20: error: reference to 'size' is ambiguous
   41 |         size[a] += size[b];
      |                    ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:30:16: note:                 'int size [100010]'
   30 | int link[nax], size[nax];
      |                ^~~~
a.cc:42:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   42 |         link[b] = a;
      |               ^
a.cc:42:17: error: assignment of read-only location '*(link + ((sizetype)b))'
   42 |         link[b] = a;
      |         ~~~~~~~~^~~
a.cc: In function 'void solve()':
a.cc:49:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   49 |         rep1(i, 1, n+1) link[i] = i, size[i] = 1;
      |                               ^
a.cc:49:33: error: assignment of read-only location '*(link + ((sizetype)i))'
   49 |         rep1(i, 1, n+1) link[i] = i, size[i] = 1;
      |                         ~~~~~~~~^~~
a.cc:49:38: error: reference to 'size' is ambiguous
   49 |         rep1(i, 1, n+1) link[i] = i, size[i] = 1;
      |                                      ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:30:16: note:                 'int size [100010]'
   30 | int link[nax], size[nax];
      |                ^~~~