Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll parent[N];
ll GroupSize[N];


ll FindLeader(ll i)
{
    if(parent[i] == i)  return i;

    return parent[i] = FindLeader(parent[i]);
}

bool SameGroup(int x, int y)
{
    int leader1 = FindLeader(x);
    int leader2 = FindLeader(y);

    return leader1 == leader2;
}


void MergeGroups(int x, int y)
{
    int leader1 = FindLeader(x);
    int leader2 = FindLeader(y);

    if(leader1 == leader2)  return;

    if(GroupSize[leader1] > GroupSize[leader2])
    {
        parent[leader2] =  leader1;
        GroupSize[leader1] += GroupSize[leader2];
    }

    else
    {
        parent[leader1] =  leader2;
        GroupSize[leader2] += GroupSize[leader1];
    }
}

ll GetSize(int x)
{
    ll leader = FindLeader(x);
    return GroupSize[leader];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    for(int i = 0; i < N; i++)
    {
        parent[i] = i;
        GroupSize[i] = 1;
    }
    vector<pair<int, int>> vec;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        vec.push_back({a, b});
    }
    reverse(vec.begin(), vec.end());
    vector<ll> res;
    ll curr = (n * (n - 1)) / 2;
    res.push_back((n * (n - 1)) / 2);
    for (int i = 0; i < m - 1; i++) {
        if (GetSize(vec[i].first) == n) {
            res.push_back(0);
            continue;
        }
        if (SameGroup(vec[i].first, vec[i].second)) {
            vec.push_back(curr);
            continue;
        }
        curr -= GetSize(vec[i].first) * GetSize(vec[i].second);
        res.push_back(curr);
        MergeGroups(vec[i].first, vec[i].second);
    }
    for (int i = res.size() - 1; i >= 0; i--)
        cout << res[i] << '\n';
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:78:26: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(ll&)'
   78 |             vec.push_back(curr);
      |             ~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'll' {aka 'long long int'} to 'const std::vector<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'll' {aka 'long long int'} to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~