Language: C++

#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,i,j,k,cc[500000],a,b,c,s ;
long long min(long long x,long long y){
	if (x>y) return y;
	else return x;
}
long long abs(long long x){
	if (x<0) return -x;
	else return x;
}
struct p{
	long long x,y,z;
	bool operator < (const p& tt) const{
		return x<tt.x;
	}
}s1[500000],s2[500000];
struct pp{
	long long x,y,z;
	bool operator < (const pp& tt) const{
		return z<tt.z;
	}
}wow[1000000];
long long find(long long x){
	if (cc[x]==x) return x;
	else {
		cc[x]= find(cc[x]);
		return cc[x];
	}
}

int main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++){
		scanf("%lld %lld",&s1[i].x,&s1[i].y);
		s2[i].x=s1[i].y;
		s2[i].y=s1[i].x;
		s1[i].z=i;
		s2[i].z=i;
	}
	sort(s1,s1+n+1);
	sort(s2,s2+n+1);
	a=0;
	for (int i=1;i<n;i++){
		a++;
		wow[i].x=s1[i].z;
		wow[i].y=s1[i+1].z;
		wow[i].z=min(abs(s1[i+1].x-s1[i].x),abs(s1[i+1].y-s1[i].y));
	}
	for (int i=1;i<n;i++){
		a++;
		wow[a].x=s2[i].z;
		wow[a].y=s2[i+1].z;
		wow[a].z=min(abs(s2[i+1].x-s2[i].x),abs(s2[i+1].y-s2[i].y));
	}	
	sort(wow,wow+a+1);
//	for (int i=1;i<=a;i++) printf("%d %d %d\n",wow[i].x,wow[i].y,wow[i].z);	
	for (int i=1;i<=n;i++) cc[i]=i;
	for (int i=1;i<=a;i++){
		if (find(cc[wow[i].x])!=find(cc[wow[i].y])){
			cc[find(cc[wow[i].x])]=find(cc[wow[i].y]);
			s+=wow[i].z;
		}
	}
	printf("%lld\n",s);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:33: error: call of overloaded 'abs(long long int)' is ambiguous
   49 |                 wow[i].z=min(abs(s1[i+1].x-s1[i].x),abs(s1[i+1].y-s1[i].y));
      |                              ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/bits/stl_algo.h:71,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:9:11: note: candidate: 'long long int abs(long long int)'
    9 | long long abs(long long x){
      |           ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:49:56: error: call of overloaded 'abs(long long int)' is ambiguous
   49 |                 wow[i].z=min(abs(s1[i+1].x-s1[i].x),abs(s1[i+1].y-s1[i].y));
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:9:11: note: candidate: 'long long int abs(long long int)'
    9 | long long abs(long long x){
      |           ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:55:33: error: call of overloaded 'abs(long long int)' is ambiguous
   55 |                 wow[a].z=min(abs(s2[i+1].x-s2[i].x),abs(s2[i+1].y-s2[i].y));
      |                              ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:9:11: note: candidate: 'long long int abs(long long int)'
    9 | long long abs(long long x){
      |           ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:55:56: error: call of overloaded 'abs(long long int)' is ambiguous
   55 |                 wow[a].z=min(abs(s2[i+1].x-s2[i].x),abs(s2[i+1].y-s2[i].y));
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:9:11: note: candidate: 'long long int abs(long long int)'
    9 | long long abs(long long x){
      |           ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~