Language: C++

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

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

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

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

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

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

long long size_tree(long long x) {
  return size[find(x)];
}
/*
 * n 島の数 
 * m 橋の数
 * a[i] - b[i];
 */
vector<long long> decayed_bridges(long long n, long long m, long long a[], long long b[]) {
  init(n);
  vector<long long> 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;
    long long 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<long long> 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(long long int)':
a.cc:13:5: error: reference to 'size' is ambiguous
   13 |     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:8:5: note:                 'int size [100000]'
    8 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(long long int, long long int)':
a.cc:35:3: error: reference to 'size' is ambiguous
   35 |   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:8:5: note:                 'int size [100000]'
    8 | int size[MAX_N];
      |     ^~~~
a.cc:35:19: error: reference to 'size' is ambiguous
   35 |   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:8:5: note:                 'int size [100000]'
    8 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'long long int size_tree(long long int)':
a.cc:43:10: error: reference to 'size' is ambiguous
   43 |   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:8:5: note:                 'int size [100000]'
    8 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:80:52: error: cannot convert 'int*' to 'long long int*'
   80 |   vector<long long> answer = decayed_bridges(n, m, a, b);
      |                                                    ^
      |                                                    |
      |                                                    int*
a.cc:50:71: note:   initializing argument 3 of 'std::vector<long long int> decayed_bridges(long long int, long long int, long long int*, long long int*)'
   50 | vector<long long> decayed_bridges(long long n, long long m, long long a[], long long b[]) {
      |                                                             ~~~~~~~~~~^~~