Submission #1866503


Source Code Expand

#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n, ans, pr[N];
struct st{int w, x, y;} a[N], b[N], c[N*2];
bool cmp(st p, st q) {return p.w<q.w;}
int f(int p) {return pr[p]==p ? p : pr[p]=f(pr[p]);}

int main() {
	int i, x, y;
	scanf("%d", &n);
	for(i=1; i<=n; i++) {
		scanf("%d%d", &a[i].w, &b[i].w);
		a[i].x = b[i].x = pr[i] = i;
	}
	sort(a+1, a+n+1, cmp);
	sort(b+1, b+n+1, cmp);
	for(i=1; i<n; i++) {
		c[i] = {a[i+1].w-a[i].w, a[i].x, a[i+1].x};
		c[i+n-1] = {b[i+1].w-b[i].w, b[i].x, b[i+1].x};
	}
	sort(c+1, c+2*n-1, cmp);
	for(i=1; i<2*n-1; i++) {
		x = f(c[i].x), y = f(c[i].y);
		if(x!=y) ans += c[i].w, pr[y] = x;
	}
	printf("%d", ans);
	return 0;
}

Submission Info

Submission Time
Task D - Built?
User t1234
Language C++14 (GCC 5.4.1)
Score 500
Code Size 724 Byte
Status AC
Exec Time 67 ms
Memory 5248 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:14:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i].w, &b[i].w);
                                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 28
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 67 ms 5248 KB
02.txt AC 67 ms 5248 KB
03.txt AC 67 ms 5248 KB
04.txt AC 67 ms 5248 KB
05.txt AC 67 ms 5248 KB
06.txt AC 67 ms 5248 KB
07.txt AC 66 ms 5248 KB
08.txt AC 66 ms 5248 KB
09.txt AC 65 ms 5248 KB
10.txt AC 63 ms 5248 KB
11.txt AC 64 ms 5248 KB
12.txt AC 64 ms 5248 KB
13.txt AC 47 ms 5248 KB
14.txt AC 47 ms 5248 KB
15.txt AC 46 ms 5248 KB
16.txt AC 48 ms 5248 KB
17.txt AC 50 ms 5248 KB
18.txt AC 49 ms 5248 KB
19.txt AC 47 ms 5248 KB
20.txt AC 48 ms 5248 KB
21.txt AC 47 ms 5248 KB
22.txt AC 49 ms 5248 KB
23.txt AC 30 ms 5248 KB
24.txt AC 40 ms 5248 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