Language: C++

#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
#define pair pair<int,int>
typedef long long ll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int mod = (int)1e9 + 7;
const ll MOD = 92709568269121;

class UnionFind{
    vector<ll> par; vector<ll> r_size;
    public:
        UnionFind(ll N) : par(N),r_size(N){
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
        }

        //Nの大きさで初期化
        void init(ll N){
            par.resize(N); r_size.resize(N);
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1;}
        }

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

        //xとyとが所属する集合を併呑する
        void unite(ll x,lly){
            ll rx = find(x); ll ry = find(y);
            if(rx == ry) return;
            if(r_size[rx]<r_size[ry]) swap(rx,ry);
            r_size[rx] += r_size[ry];
            par[ry] = rx;
        }

        bool same(ll x, ll y){
            ll ry = find(x); ll rx = find(y);
            return rx == ry;
        }

        //素集合の大きさを返す
        ll el_size(ll x){
            return r_size[find(x)];
        }
};

int main(){
    ll n,m,a,b; cin>>n>>m;
    vector<pair> input(m);
    rep(i,m){ cin>>a>>b; input[i].first = --a; input[i].second = --b;}

    UnionFind island(n);
    vector<ll> ans(m);

    ans[0] = (n*(n-1))/2;
    reverse(input.begin(),input.end());

    ll x,y; ll con;
    rep(i,m-1){
        x = input[i].first; y = input[i].second;
        if(island.same(x,y)){
            ans[i+1] = ans[i];
        }else{
            con = island.el_size(x)*island.el_size(y);
            ans[i+1] = max(ans[i]-con, 0);
            island.unite(x,y);
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto x:ans)cout<<x<<endl; return 0;
}


Compiler output:
a.cc:43:25: error: 'lly' has not been declared
   43 |         void unite(ll x,lly){
      |                         ^~~
a.cc: In member function 'void UnionFind::unite(ll, int)':
a.cc:44:43: error: 'y' was not declared in this scope; did you mean 'yn'?
   44 |             ll rx = find(x); ll ry = find(y);
      |                                           ^
      |                                           yn
a.cc: In function 'int main()':
a.cc:80:27: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   80 |             ans[i+1] = max(ans[i]-con, 0);
      |                        ~~~^~~~~~~~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:80:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   80 |             ans[i+1] = max(ans[i]-con, 0);
      |                        ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:12:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:80:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   80 |             ans[i+1] = max(ans[i]-con, 0);
      |                        ~~~^~~~~~~~~~~~~~~