Language: C++

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int MAX_ROAD = 400001; 
int nl[MAX_ROAD], nr[MAX_ROAD];
class DisjointSet
{
    private:
        unsigned int size;  
        int * a;    
    public:
        DisjointSet() { size = 0; a = NULL; }
        DisjointSet(unsigned int _size)
        {
            size = _size;
            a = new int[size+1];
            memset(a, -1, (size+1)*sizeof(int));    
        ~DisjointSet() { delete [] a; }
        int find(int x)     
        {
            if ( x <= 0 || x > size )  
                return -1;
            if ( a[x] < 0 )    
                return x;
            a[x] = find(a[x]); 
            return a[x];
        } 
        bool unionset(int x, int y)   
        {
            int rx = find(x);
            int ry = find(y);
            if ( rx < 0 || ry < 0 || rx == ry )   
                return false;
            if ( a[rx] < a[ry]  )   
            {
                a[rx] += a[ry];
                a[ry] = rx; 
            }
            else
            {
                a[ry] += a[rx];
                a[rx] = ry;
            }
            return true;
        } 
}; 
int main()
{
    int n_city = 0, n_road = 0;   
    scanf("%d %d", &n_city, &n_road);   
    
    for ( int i = 1; i <= n_road; ++i ) 
        scanf("%d %d", nl+i, nr+i); 
    
    DisjointSet c(n_city);
    int n_choice = 0;   
    vector<int> ans;    
    for ( int i = n_road; n_choice < n_city && i > 0; --i )    
    {
        int sl = c.find(nl[i]), sr = c.find(nr[i]);   
        if ( sl != sr )    
        {
            ++n_choice;
            ans.push_back(i);
            c.unionset(sl, sr);
        } 
    } 
    printf("%d\n", n_choice);
    for ( int i = n_choice - 1; i >=0; --i )
        printf("%d\n", ans[i]); 
    return 0;
} 

Compiler output:
a.cc:73:2: error: expected '}' at end of input
   73 | }
      |  ^
a.cc:8:1: note: to match this '{'
    8 | {
      | ^
a.cc: In constructor 'DisjointSet::DisjointSet(unsigned int)':
a.cc:19:9: error: no match for 'operator~' (operand type is 'DisjointSet')
   19 |         ~DisjointSet() { delete [] a; }
      |         ^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:38,
                 from /usr/include/c++/14/vector:87,
                 from a.cc:3:
/usr/include/c++/14/cstddef:151:3: note: candidate: 'constexpr std::byte std::operator~(byte)'
  151 |   operator~(byte __b) noexcept
      |   ^~~~~~~~
/usr/include/c++/14/cstddef:151:18: note:   no known conversion for argument 1 from 'DisjointSet' to 'std::byte'
  151 |   operator~(byte __b) noexcept
      |             ~~~~~^~~
a.cc:21:9: error: a function-definition is not allowed here before '{' token
   21 |         {
      |         ^
a.cc:30:9: error: a function-definition is not allowed here before '{' token
   30 |         {
      |         ^
a.cc: In member function 'int DisjointSet::main()':
a.cc:61:20: error: 'class DisjointSet' has no member named 'find'
   61 |         int sl = c.find(nl[i]), sr = c.find(nr[i]);
      |                    ^~~~
a.cc:62:20: error: 'sr' was not declared in this scope; did you mean 'nr'?
   62 |         if ( sl != sr )
      |                    ^~
      |                    nr
a.cc:66:15: error: 'class DisjointSet' has no member named 'unionset'
   66 |             c.unionset(sl, sr);
      |               ^~~~~~~~
a.cc: At global scope:
a.cc:73:2: error: expected unqualified-id at end of input
   73 | }
      |  ^