Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

const int MAX_N = 100;

int par[MAX_N];
int rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
    }
    size = n;
}

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

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (rank[x] < rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank[x] == rank[y]) {
            rank[x]++;
        }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int a[M], b[M];
    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    int ans = 0;
    rep(i, M) {
        init(N);
        rep(j ,M) {
            if (i == j) continue;
            unite(a[j], b[j]);
        }
        //dump(size);
        if (size != 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:19:9: error: reference to 'rank' is ambiguous
   19 |         rank[i] = 0;
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100]'
   13 | int rank[MAX_N];
      |     ^~~~
a.cc:21:5: error: reference to 'size' is ambiguous
   21 |     size = n;
      |     ^~~~
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:14:5: note:                 'int size'
   14 | int size;
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:37:5: error: reference to 'size' is ambiguous
   37 |     size--;
      |     ^~~~
/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:14:5: note:                 'int size'
   14 | int size;
      |     ^~~~
a.cc:38:9: error: reference to 'rank' is ambiguous
   38 |     if (rank[x] < rank[y]) {
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100]'
   13 | int rank[MAX_N];
      |     ^~~~
a.cc:38:19: error: reference to 'rank' is ambiguous
   38 |     if (rank[x] < rank[y]) {
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100]'
   13 | int rank[MAX_N];
      |     ^~~~
a.cc:42:13: error: reference to 'rank' is ambiguous
   42 |         if (rank[x] == rank[y]) {
      |             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100]'
   13 | int rank[MAX_N];
      |     ^~~~
a.cc:42:24: error: reference to 'rank' is ambiguous
   42 |         if (rank[x] == rank[y]) {
      |                        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100]'
   13 | int rank[MAX_N];
      |     ^~~~
a.cc:43:13: error: reference to 'rank' is ambiguous
   43 |             rank[x]++;
      |             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100]'
   13 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:71:13: error: reference to 'size' is ambiguous
   71 |         if (size != 1) ans++;
      |             ^~~~
/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:14:5: note:                 'int size'
   14 | int size;
      |     ^~~~