Language: C++

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

int main() {
  int N, M;
  cin >>N >>M;// 島数、橋数
  vector<int> I(N+1, 0);// 島
  vector<int> A(M+1);// 橋始点
  vector<int> B(M+1);// 橋終点
  vector<long> F(M+1);// 取り除いた橋の数に対する不便さ
  vector<int> C(M/2+2, 0);// 島 Group 内の島数
  vector<vector<int>> L(N+1, vector<int>(0));
  long S=N*((long)N-1)/2;// 最初の不便さ
  // 橋読み込み
  for (int i=1; i<=M; i++) {
    cin >>A.at(i) >>B.at(i);
  }
  F.at(M)=S;/// 最初の（M 個の橋を取り除いたときの）不便さ
  int num=0;/// 島 Group#
  int nn;
  for (int i=M; i>0; i--) {
    int a=A.at(i);
    int b=B.at(i);
    //cout << a << ":" << b << ":" << I.at(a) << ":" << I.at(b) << endl;/////////////
    if ((I.at(a)==0) && (I.at(b)==0)) {
      num++;
      //cout <<"0-0:"<< a << ":" << b << endl;////
      I.at(a)=I.at(b)=num;/// 新 Group： num
      S--;/// 解消された不便さ
      C.at(num)=2;///// num の島の数
      L.at(num)={a, b};
      /*//////////////////////////
      for (int jj=0; jj<L.at(num).size(); jj++)
        cout << L.at(num).at(jj);
      cout << endl;
      */////////////////////////
    } else if (I.at(a)==0) {
      //cout <<"0-X:"<< a << ":" << b << endl;////
      I.at(a)=nn=I.at(b);
      S-=C.at(nn);/// 解消された不便さ
      C.at(nn)++;/// num の島の数
      L.at(nn).insert(L.at(nn).end(), {a});
      /*//////////////////////////
      for (int jj=0; jj<L.at(nn).size(); jj++)
        cout << L.at(nn).at(jj);
      cout << endl;
      */////////////////////////
    } else if (I.at(b)==0) {
      //cout <<"X-0:"<< a << ":" << b << endl;////
      I.at(b)=nn=I.at(a);
      S-=C.at(nn);/// 解消された不便さ
      C.at(nn)++;/// num の島の数
      L.at(nn).insert(L.at(nn).end(), {b});
      /*//////////////////////////
      for (int jj=0; jj<L.at(nn).size(); jj++)
        cout << L.at(nn).at(jj);
      cout << endl;
      */////////////////////////
    } else if (I.at(a)!=I.at(b)) {
      S-=C.at(I.at(a))*C.at(I.at(b));/// 解消された不便さ
      C.at(I.at(a))+=C.at(I.at(b));/// num の島の数
      //C.at(I.at(b)=0;/// Not required
      nn=I.at(a);
      int Ib=I.at(b);
      for (int j=0; j<L.at(Ib).size(); j++)
        I.at(L.at(Ib).at(j))=nn;
      L.at(nn).insert(L.at(nn).end(), L.at(Ib).begin(), L.at(Ib).end());
      L.at(Ib).erase(L.at(Ib)begin(), L.at(Ib).end());
      /*//////////////////////////
      for (int jj=0; jj<L.at(nn).size(); jj++)
        cout << L.at(nn).at(jj);
      cout << endl;
      */////////////////////////
    } else {
      /// Do nothing
    }
    //cout << i-1 << ":" << S << endl;/////
    F.at(i-1)=S;
  }
  for (int i=1; i<=M; i++)
    cout << F.at(i) << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:68:30: error: expected ')' before 'begin'
   68 |       L.at(Ib).erase(L.at(Ib)begin(), L.at(Ib).end());
      |                     ~        ^~~~~
      |                              )
a.cc:68:21: error: no matching function for call to 'std::vector<int>::erase(__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type&, std::vector<int>::iterator)'
   68 |       L.at(Ib).erase(L.at(Ib)begin(), L.at(Ib).end());
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::vector<int>::const_iterator'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |             ~~~~~~~~~~~~~~~^~~~~~~