Submission #1866482
Source Code Expand
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
typedef long long ll;
ll n, ans, pr[N];
struct st{ll x, y, z;} a[N], b[N*2];
bool cmp1(st p, st q) {return p.x<q.x;}
bool cmp2(st p, st q) {return p.y<q.y;}
bool cmp3(st p, st q) {return p.z<q.z;}
ll f(ll p) {
if(pr[p]==p) return p;
return pr[p] = f(pr[p]);
}
int main() {
ll i, x, y;
scanf("%lld", &n);
for(i=1; i<=n; i++) scanf("%lld%lld", &a[i].x, &a[i].y), a[i].z=pr[i]=i;
sort(a+1, a+n+1, cmp1);
for(i=1; i<n; i++) b[i] = {a[i].z, a[i+1].z, a[i+1].x-a[i].x};
sort(a+1, a+n+1, cmp2);
for(i=1; i<n; i++) b[i+n-1] = {a[i].z, a[i+1].z, a[i+1].y-a[i].y};
sort(b+1, b+2*n-1, cmp3);
for(i=1; i<2*n-1; i++) {
x = f(b[i].x), y = f(b[i].y);
if(x!=y) ans += b[i].z, pr[y] = x;
}
printf("%lld", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Built? |
User |
t1234 |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
833 Byte |
Status |
AC |
Exec Time |
85 ms |
Memory |
7936 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:19:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
^
./Main.cpp:20:73: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=n; i++) scanf("%lld%lld", &a[i].x, &a[i].y), a[i].z=pr[i]=i;
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
80 ms |
7936 KB |
02.txt |
AC |
80 ms |
7936 KB |
03.txt |
AC |
80 ms |
7936 KB |
04.txt |
AC |
80 ms |
7936 KB |
05.txt |
AC |
80 ms |
7936 KB |
06.txt |
AC |
79 ms |
7936 KB |
07.txt |
AC |
85 ms |
7936 KB |
08.txt |
AC |
80 ms |
7936 KB |
09.txt |
AC |
77 ms |
7936 KB |
10.txt |
AC |
77 ms |
7936 KB |
11.txt |
AC |
77 ms |
7936 KB |
12.txt |
AC |
76 ms |
7936 KB |
13.txt |
AC |
58 ms |
7936 KB |
14.txt |
AC |
58 ms |
7936 KB |
15.txt |
AC |
52 ms |
7936 KB |
16.txt |
AC |
52 ms |
7936 KB |
17.txt |
AC |
54 ms |
7936 KB |
18.txt |
AC |
55 ms |
7936 KB |
19.txt |
AC |
53 ms |
7936 KB |
20.txt |
AC |
53 ms |
7936 KB |
21.txt |
AC |
52 ms |
7936 KB |
22.txt |
AC |
54 ms |
7936 KB |
23.txt |
AC |
40 ms |
7936 KB |
24.txt |
AC |
51 ms |
7936 KB |
25.txt |
AC |
1 ms |
2176 KB |
26.txt |
AC |
1 ms |
2176 KB |
s1.txt |
AC |
1 ms |
2176 KB |
s2.txt |
AC |
1 ms |
2176 KB |