Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// マラソン用時間計測
clock_t start_clock;
constexpr double time_limit = 1.919114514; // 実行時間[s]より0.1ms程度余裕をあける
constexpr double CLOCKS_PER_SEC_INV = 1.0 / CLOCKS_PER_SEC;
inline double nowtime() { return CLOCKS_PER_SEC_INV * (clock() - start_clock); }
inline bool intime() { return nowtime() < time_limit; }

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (int i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (int i=(is), i##_end=(ie); i<=i##_end; i++)
#define FOREACH(i, arr) for (auto &i : arr)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using ll = long long;
using namespace std;

// 汎用クラス
struct union_find {
    vector<int> par;
    vector<int> num;
    union_find(int n) : par(n, 0), num(n, 1) { iota(ALL_OF(par), 0); }
    int root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }
    bool same(int i, int j) { return root(i) == root(j); }
    void unite(int i, int j) {
        int ri = root(i);
        int rj = root(j);
        if (ri != rj) {
            if (num[ri] > num[rj]) swap(ri, rj);
            par[ri] = rj;
            num[rj] += num[ri];
        }
    }
};

// main前実行のためのダミークラス
class preexec_dummy {
    preexec_dummy() {
        start_clock = clock();
    }
} preexec_dummy_instance;

// Let's comp(u|e)te!
int main() {
    
    int n, m;
    cin >> n >> m;
    vector<int> a(m, 0), b(m, 0);
    UnionFind uf(n);
    REP(i, m) {
        cin >> a[i] >> b[i];
        // make them 0-indexed
        a[i]--;
        b[i]--;
    }

    vector<ll> ans(m, 0);
    ans[m-1] = (ll)n * ((ll)n - 1ll) / 2ll;
    for (int i = m-1; i--;) {

        if (!uf.same(a[i+1], b[i+1])) {
            int na = uf.num[uf.root(a[i+1])];
            int nb = uf.num[uf.root(b[i+1])];
            ans[i] = ans[i+1] - (ll)na * (ll)nb;
            uf.unite(a[i+1], b[i+1]);
        } else {
            ans[i] = ans[i+1];
        }

    }

    REP(i, m) cout << ans[i] << endl;
    
}

Compiler output:
a.cc:60:3: error: 'preexec_dummy::preexec_dummy()' is private within this context
   60 | } preexec_dummy_instance;
      |   ^~~~~~~~~~~~~~~~~~~~~~
a.cc:57:5: note: declared private here
   57 |     preexec_dummy() {
      |     ^~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:68:5: error: 'UnionFind' was not declared in this scope; did you mean 'union_find'?
   68 |     UnionFind uf(n);
      |     ^~~~~~~~~
      |     union_find
a.cc:80:14: error: 'uf' was not declared in this scope
   80 |         if (!uf.same(a[i+1], b[i+1])) {
      |              ^~