Language: C++

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

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

void unite(int x, int y, int par[], int size[]){
    x = find(x, par);
    y = find(y, par);
    if(x==y){
        return;
    }
    size[x] += size[y];
    par[y] = x;
    return;
}
 
int main(){
    int n, m, i;
    cin >> n >> m;
    int a[m], b[m], par[n], size[n];
    long int ans[m];
    for(i=0; i<n; i++){
        par[i] = i;
        size[i] = 1;
    }
    for(i=0; i<m; i++){
        cin >> a[i] >> b[m];
    }
    for(i=m-1; i>=0; i--){
        if(i == m-1){
            ans[i] = n*(n-1)/2;
        }else if(find(a[i], par) != find(b[i], par){
            int x = find(a[i], par), y = find(b[i], par);
            ans[i] = ans[i+1] - size[x]*size[y];
            unite(x, y, par, size);
        }
    }
    for(i=0; i<m; i++){
        cout << ans[i];
    }
    return 0;
}

Compiler output:
a.cc: In function 'int find(int, int*)':
a.cc:8:29: error: no matching function for call to 'find(int&)'
    8 |         return par[x] = find(par[x]);
      |                         ~~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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/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:4:5: note: candidate: 'int find(int, int*)'
    4 | int find(int x, int par[]){
      |     ^~~~
a.cc:4:5: note:   candidate expects 2 arguments, 1 provided
a.cc: In function 'int main()':
a.cc:38:52: error: expected ')' before '{' token
   38 |         }else if(find(a[i], par) != find(b[i], par){
      |                 ~                                  ^
      |                                                    )
a.cc:43:5: error: expected primary-expression before '}' token
   43 |     }
      |     ^