Language: C++

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

#define int long long

typedef  pair<int, int> iPair;
struct Graph
{
    int V, E;
    vector< pair<int, iPair> > edges;
    
    Graph(int V, int E)
    {
        this->V = V;
        this->E = E;
    }
    void addEdge(int u, int v, int w)
    {
        edges.push_back({w, {u, v}});
    }
    int kruskalMST();
};

struct data{
	int x, y, weight;
}edges2[100001];
bool cmp1(int a, int b){
	if(edges2[a].first > edges2[b].first || (edges2[a].second > edges2[b].second && edges2[a].first == edges2[b].first)) return true;
	else return false;
}

bool cmp2(int a, int b){
	if(edges2[a].second > edges2[b].second || (edges2[a].first > edges2[b].first && edges2[a].second == edges2[b].second)) return true;
	else return false;
}

struct DisjointSets
{
    int *parent, *rnk;
    int n;
    DisjointSets(int n)
    {
        this->n = n;
        parent = new int[n+1];
        rnk = new int[n+1];
        for (int i = 0; i <= n; i++)
        {
            rnk[i] = 0;
            parent[i] = i;
        }
    }
    int find(int u)
    {
        if (u != parent[u])
            parent[u] = find(parent[u]);
        return parent[u];
    }

    void merge(int x, int y)
    {
        x = find(x), y = find(y);
        if (rnk[x] > rnk[y])
            parent[y] = x;
        else
            parent[x] = y;

        if (rnk[x] == rnk[y])
            rnk[y]++;
    }
};

int Graph::kruskalMST()
{
    int mst_wt = 0;
    sort(edges.begin(), edges.end());
    DisjointSets ds(V);
    vector< pair<int, iPair> >::iterator it;
    for (it=edges.begin(); it!=edges.end(); it++)
    {
        int u = it->second.first;
        int v = it->second.second;

        int set_u = ds.find(u);
        int set_v = ds.find(v);
        if (set_u != set_v)
        {
            cout << u << " - " << v << endl;
            mst_wt += it->first;
            ds.merge(set_u, set_v);
        }
    }

    return mst_wt;
}

signed main()
{
	int n, x, y;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x >> y;
		edges2.push_back(make_pair(x, y));
	} 
    Graph(n, 2*(n-1));
    sort(edges2, edges2 + n, cmp1);
    for(int i = 0; i < n-1; i++) Graph.push_back(i, i + 1, min(abs(edges2[i].first-edges2[i+1].first), abs(edges2[i].second-edges2[i+1].second));
    sort(edges2, edges2 + n, cmp2);
    for(int i = 0; i < n-1; i++) Graph.push_back(i, i + 1, min(abs(edges2[i].first-edges2[i+1].first), abs(edges2[i].second-edges2[i+1].second));
    int mst_wt = g.kruskalMST();
    cout << mst_wt;
    return 0;
}

Compiler output:
a.cc: In function 'bool cmp1(long long int, long long int)':
a.cc:28:22: error: 'struct data' has no member named 'first'
   28 |         if(edges2[a].first > edges2[b].first || (edges2[a].second > edges2[b].second && edges2[a].first == edges2[b].first)) return true;
      |                      ^~~~~
a.cc:28:40: error: 'struct data' has no member named 'first'
   28 |         if(edges2[a].first > edges2[b].first || (edges2[a].second > edges2[b].second && edges2[a].first == edges2[b].first)) return true;
      |                                        ^~~~~
a.cc:28:60: error: 'struct data' has no member named 'second'
   28 |         if(edges2[a].first > edges2[b].first || (edges2[a].second > edges2[b].second && edges2[a].first == edges2[b].first)) return true;
      |                                                            ^~~~~~
a.cc:28:79: error: 'struct data' has no member named 'second'
   28 |         if(edges2[a].first > edges2[b].first || (edges2[a].second > edges2[b].second && edges2[a].first == edges2[b].first)) return true;
      |                                                                               ^~~~~~
a.cc:28:99: error: 'struct data' has no member named 'first'
   28 |         if(edges2[a].first > edges2[b].first || (edges2[a].second > edges2[b].second && edges2[a].first == edges2[b].first)) return true;
      |                                                                                                   ^~~~~
a.cc:28:118: error: 'struct data' has no member named 'first'
   28 |         if(edges2[a].first > edges2[b].first || (edges2[a].second > edges2[b].second && edges2[a].first == edges2[b].first)) return true;
      |                                                                                                                      ^~~~~
a.cc: In function 'bool cmp2(long long int, long long int)':
a.cc:33:22: error: 'struct data' has no member named 'second'
   33 |         if(edges2[a].second > edges2[b].second || (edges2[a].first > edges2[b].first && edges2[a].second == edges2[b].second)) return true;
      |                      ^~~~~~
a.cc:33:41: error: 'struct data' has no member named 'second'
   33 |         if(edges2[a].second > edges2[b].second || (edges2[a].first > edges2[b].first && edges2[a].second == edges2[b].second)) return true;
      |                                         ^~~~~~
a.cc:33:62: error: 'struct data' has no member named 'first'
   33 |         if(edges2[a].second > edges2[b].second || (edges2[a].first > edges2[b].first && edges2[a].second == edges2[b].second)) return true;
      |                                                              ^~~~~
a.cc:33:80: error: 'struct data' has no member named 'first'
   33 |         if(edges2[a].second > edges2[b].second || (edges2[a].first > edges2[b].first && edges2[a].second == edges2[b].second)) return true;
      |                                                                                ^~~~~
a.cc:33:99: error: 'struct data' has no member named 'second'
   33 |         if(edges2[a].second > edges2[b].second || (edges2[a].first > edges2[b].first && edges2[a].second == edges2[b].second)) return true;
      |                                                                                                   ^~~~~~
a.cc:33:119: error: 'struct data' has no member named 'second'
   33 |         if(edges2[a].second > edges2[b].second || (edges2[a].first > edges2[b].first && edges2[a].second == edges2[b].second)) return true;
      |                                                                                                                       ^~~~~~
a.cc: In function 'int main()':
a.cc:102:24: error: request for member 'push_back' in 'edges2', which is of non-class type 'data [100001]'
  102 |                 edges2.push_back(make_pair(x, y));
      |                        ^~~~~~~~~
a.cc:106:39: error: expected unqualified-id before '.' token
  106 |     for(int i = 0; i < n-1; i++) Graph.push_back(i, i + 1, min(abs(edges2[i].first-edges2[i+1].first), abs(edges2[i].second-edges2[i+1].second));
      |                                       ^
a.cc:108:39: error: expected unqualified-id before '.' token
  108 |     for(int i = 0; i < n-1; i++) Graph.push_back(i, i + 1, min(abs(edges2[i].first-edges2[i+1].first), abs(edges2[i].second-edges2[i+1].second));
      |                                       ^
a.cc:109:18: error: 'g' was not declared in this scope
  109 |     int mst_wt = g.kruskalMST();
      |                  ^
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 = data*; _Iterator2 = data*; _Compare = bool (*)(long long int, long long int)]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(long long int, long long int)>]'
 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 = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(long long int, long long int)>]'
 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 = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(long long int, long long int)>]'
 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 = data*; _Compare = bool (*)(long long int, long long int)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:105:9:   required from here
  105 |     sort(edges2, edges2 + n, cmp1);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: cannot convert 'data' to 'long long int' in argument passing
  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 = data; _Iterator = data*; _Compare = bool (*)(long long int, long long int)]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = data*; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool (*)(long long int, long long int)>]'
 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 = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(long long int, long long int)>]'
 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 = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(long long int, long long int)>]'
 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 = data*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(long long int, long long int)>]'
 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 = data*; _Compare = bool (*)(long long int, long long int)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:105:9:   required from here
  105 |     sort(edges2, edges2 + n, cmp1);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:240:30: error: cannot convert 'data' to 'long long int' in argument passing
  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 = data*; _Value = data; _Compare = bool (*)(long long int, long long int)]':
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = data*; _Distance = long int; _Tp = data; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(long long int, long long int)>]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |