Language: C++

#include <iostream>
#include <vector>
#define MAX_N 100000
using namespace std;

int par[MAX_N];
int size[MAX_N];

void init(int n) {
  for(int i=0;i<n;i++) {
    par[i] = i;
    size[i] = 1;
  }
}

// rootを返す
int find(int x) {
  if(par[x] == x) {
    return x;
  }
  int root = find(par[x]);
  par[x] = root;
  return root;
}

void unite(int x, int y) {
  // 親どうし
  int root_x = find(x);
  int root_y = find(y);
  if (root_x == root_y) {
    return;
  }
  par[root_y] = root_x;
  size[root_x] += size[root_y];
}

bool same(int x, int y) {
  return find(x) == find(y);
}

int size_tree(int x) {
  return size[find(x)];
}
/*
 * n 島の数 
 * m 橋の数
 * a[i] - b[i];
 */
vector<int> decayed_bridges(int n, int m, int a[], int b[]) {
  init(n);
  vector<int> answer;
  answer.push_back((n * (n-1)) / 2);
  for(int i=m-1;i>=1;i--) {
    int aa = a[i] - 1;
    int bb = b[i] - 1;
    int last = answer[answer.size() - 1];
    if(same(aa, bb)) {
      answer.push_back(last);
      continue;
    }
    answer.push_back(last - size_tree(aa) * size_tree(bb));
    unite(aa, bb);
  }
  reverse(answer.begin(), answer.end());
  return answer;
}


int main() {
  int n, m;
  cin >> n;
  cin >> m;
  int a[m];
  int b[m];
  for(int i=0;i<m;i++) {
    cin >> a[i];
    cin >> b[i];
  }
  vector<int> answer = decayed_bridges(n, m, a, b);
  for(int i=0;i<answer.size();i++) {
    cout << answer[i];
    if(i != answer.size())
      cout << endl;
  }
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:12:5: error: reference to 'size' is ambiguous
   12 |     size[i] = 1;
      |     ^~~~
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:7:5: note:                 'int size [100000]'
    7 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:34:3: error: reference to 'size' is ambiguous
   34 |   size[root_x] += size[root_y];
      |   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:7:5: note:                 'int size [100000]'
    7 | int size[MAX_N];
      |     ^~~~
a.cc:34:19: error: reference to 'size' is ambiguous
   34 |   size[root_x] += size[root_y];
      |                   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:7:5: note:                 'int size [100000]'
    7 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'int size_tree(int)':
a.cc:42:10: error: reference to 'size' is ambiguous
   42 |   return size[find(x)];
      |          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:7:5: note:                 'int size [100000]'
    7 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'std::vector<int> decayed_bridges(int, int, int*, int*)':
a.cc:64:3: error: 'reverse' was not declared in this scope
   64 |   reverse(answer.begin(), answer.end());
      |   ^~~~~~~