Language: C++

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

void disp(vector<int> p, int n){
	for(int i=0; i<n; i++){
		cout << p[i] << ", ";
	}
	cout << endl;

}
bool isRoot(vector<int> p, int a){
	return p[a] < 0;
}

int root(vector<int> &p, int a){
	if(isRoot(p, a)) return a;
	return p[a] = root(p, p[a]);
}

void joint(vector<int> &p, vector<int> &ccnt, int a, int b){
  int ra = root(p, a);
  int rb = root(p, b);
  if(ra == rb) return;
  
  if(p[ra] == p[rb]){
    p[rb] = ra;
    p[ra]--;
	ccnt[ra] += ccnt[rb];
  } else if(p[ra] < p[rb]) {
    p[rb] = ra;
	ccnt[ra] += ccnt[rb];
  } else {
    p[ra] = rb;
	ccnt[rb] += ccnt[ra];
  }
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	for(int i=0; i<m; i++){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}

	vector<long long int> fuben(m, 0);
	vector<int> parent(n, -1);
	vector<int> childCnt(n, 1);

	fuben[m-1] = (long long int) n * (n-1) / 2;
	for(int i=m-2; i>=0; i--){
		joint(parent, childCnt, a[i], b[i]);
		fuben[i] = fuben[i+1] - childCnt[root(a[i])] * childCnt[root(a[b])];
	}

	for(int i=0; i<m; i++) cout << fuben[i] << "\n";
	cout << flush;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:54: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   55 |                 fuben[i] = fuben[i+1] - childCnt[root(a[i])] * childCnt[root(a[b])];
      |                                                  ~~~~^~~~~~
a.cc:15:23: note: in passing argument 1 of 'int root(std::vector<int>&, int)'
   15 | int root(vector<int> &p, int a){
      |          ~~~~~~~~~~~~~^
a.cc:55:79: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::vector<int>')
   55 |                 fuben[i] = fuben[i+1] - childCnt[root(a[i])] * childCnt[root(a[b])];
      |                                                                               ^
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:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~