Language: C++

#include<bits/stdc++.h>

using namespace std;

struct edge{
        int u, v, cost;
};

struct node{
        int x, y, id;
};

int pare[100000];
int trank[100000];

bool xcomp(node& x, node& y){
        return x.x<y.x;
}
bool ycomp(node& x, node& y){
        return x.y<y.y;
}
bool ccomp(node& x, node& y){
        return x.cost<y.cost;
}


int find(int u){
        if(u==pare[u])
                return u;
        return pare[u]=find(pare[u]);
}

void unite(int u, int v){
        u=find(u);
        v=find(v);
        if(u==v)
                return;
        if(trank[u]<trank[v]){
                pare[u]=v;
        }
        else{
                pare[v]=u;
                if(trank[u]==trank[v]){
                        trank[u]++;
                }
        }
        return;
}


int main(){
        int N;
        cin>>N;
        vector <edge> edge;
        vector <node> node;
        for(int i=0;i<N;i++){
                int x, y;
                cin>>x>>y;
                node n;
                n.x=x;n.y=y;n.id=i;
                node.push_back(n);
                pare[i]=i;
                trank[i]=0;
        }
        sort(node.begin(), node.end(), xcomp);
        for(int i=0;i<N-1;i++){
                edge e;
                e.u=node[i].id;
                e.v=node[i+1].id;
                e.cost=node[i+1].x-node[i].x;
        }
        sort(node.begin(), node.end(), ycomp);
        for(int i=0;i<N-1;i++){
                Edge e;
                e.u=node[i].id;
                e.v=node[i+1].id;
                e.cost=node[i+1].y-node[i].y;
                edge.push_back(e);
        }
        sort(edge.begin(), edge.end(), ccomp);
        long long res=0;
        for(int i=0;i<(int)edge.size();i++){
                edge e=edge[i];
                if(find(e.u)!=find(e.v)){
                        ans+=e.cost;
                        unite(e.u, e.v);
                }
        }
        cout<<res<<endl;
        return 0;
}


Compiler output:
a.cc: In function 'bool ccomp(node&, node&)':
a.cc:23:18: error: 'struct node' has no member named 'cost'
   23 |         return x.cost<y.cost;
      |                  ^~~~
a.cc:23:25: error: 'struct node' has no member named 'cost'
   23 |         return x.cost<y.cost;
      |                         ^~~~
a.cc: In function 'int main()':
a.cc:59:21: error: expected ';' before 'n'
   59 |                 node n;
      |                     ^~
      |                     ;
a.cc:60:17: error: 'n' was not declared in this scope
   60 |                 n.x=x;n.y=y;n.id=i;
      |                 ^
a.cc:67:21: error: expected ';' before 'e'
   67 |                 edge e;
      |                     ^~
      |                     ;
a.cc:68:17: error: 'e' was not declared in this scope
   68 |                 e.u=node[i].id;
      |                 ^
a.cc:74:17: error: 'Edge' was not declared in this scope; did you mean 'edge'?
   74 |                 Edge e;
      |                 ^~~~
      |                 edge
a.cc:75:17: error: 'e' was not declared in this scope
   75 |                 e.u=node[i].id;
      |                 ^
a.cc:83:21: error: expected ';' before 'e'
   83 |                 edge e=edge[i];
      |                     ^~
      |                     ;
a.cc:84:25: error: 'e' was not declared in this scope
   84 |                 if(find(e.u)!=find(e.v)){
      |                         ^
a.cc:85:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   85 |                         ans+=e.cost;
      |                         ^~~
      |                         abs
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<edge*, std::vector<edge> >; _Iterator2 = __gnu_cxx::__normal_iterator<edge*, std::vector<edge> >; _Compare = bool (*)(node&, node&)]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = bool (*)(node&, node&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:80:13:   required from here
   80 |         sort(edge.begin(), edge.end(), ccomp);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: invalid initialization of reference of type 'node&' from expression of type 'edge'
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = edge; _Iterator = __gnu_cxx::__normal_iterator<edge*, std::vector<edge> >; _Compare = bool (*)(node&, node&)]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool (*)(node&, node&)>]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1785:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1785 |             std::__unguarded_linear_insert(__i,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
 1786 |                                 __gnu_cxx::__ops::__val_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = bool (*)(node&, node&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:80:13:   required from here
   80 |         sort(edge.begin(), edge.end(), ccomp);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:240:30: error: invalid initialization of reference of type 'node&' from expression of type 'edge'
  240 |         { return bool(_M_comp(__val, *__it)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<edge*, std::vector<edge> >; _Value = edge; _Compare = bool (*)(node&, node&)]':
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Distance = long int; _Tp = edge; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(node&, node&)>]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:247:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Distance = long int; _Tp = edge; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
  247 |       std::__push_heap(__first, __holeIndex, __topIndex,
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248 |                        _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:356:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
  356 |           std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
      |           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357 |                              __comp);
      |                              ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1593:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1593 |       std::__make_heap(__first, __middle, __comp);
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1868:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(node&, node&)>]'
 1868 |       std::__heap_select(__first, __middle, __last, __comp);
      |       ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1884:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<edge*, vector<edge> >; _Size = long int; _Compare = __gnu_