Submission #2529921


Source Code Expand

# -*- coding: utf-8 -*-
from heapq import heappop, heappush
def inpl(): return map(int, input().split())
N = int(input())

X = []
Y = []

for i in range(N):
    x, y = inpl()
    X.append((i, x))
    Y.append((i, y))

X = sorted(X, key=lambda x: x[1])
Y = sorted(Y, key=lambda y: y[1])

G = [[] for _ in range(N)]
for i in range(N-1):
    Xa, Xb = X[i], X[i+1]
    Ya, Yb = Y[i], Y[i+1]
    G[Xa[0]].append([Xb[0], Xb[1]-Xa[1]])
    G[Xb[0]].append([Xa[0], Xb[1]-Xa[1]])
    
    G[Ya[0]].append([Yb[0], Yb[1]-Ya[1]])
    G[Yb[0]].append([Ya[0], Yb[1]-Ya[1]])

visited = [False]*N
Q = [(0, 0)]
ans = 0

while Q:
    c, n = heappop(Q)
    if visited[n]:
        continue
    visited[n] = True
    ans += c
    
    for m, d in G[n]:
        if visited[m]:
            continue
        else:
            heappush(Q, (d, m))

print(ans)

Submission Info

Submission Time
Task D - Built?
User nadare881
Language Python (3.4.3)
Score 0
Code Size 876 Byte
Status TLE
Exec Time 2109 ms
Memory 96608 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 19
TLE × 9
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 TLE 2107 ms 96580 KB
02.txt TLE 2107 ms 96576 KB
03.txt TLE 2107 ms 96576 KB
04.txt TLE 2009 ms 96592 KB
05.txt TLE 2109 ms 96580 KB
06.txt TLE 2109 ms 96608 KB
07.txt AC 1938 ms 96564 KB
08.txt TLE 2109 ms 96552 KB
09.txt AC 1935 ms 95376 KB
10.txt TLE 2107 ms 95348 KB
11.txt AC 1955 ms 95360 KB
12.txt TLE 2102 ms 95316 KB
13.txt AC 1669 ms 87552 KB
14.txt AC 1680 ms 87420 KB
15.txt AC 1605 ms 77436 KB
16.txt AC 1743 ms 77512 KB
17.txt AC 1789 ms 90140 KB
18.txt AC 1635 ms 90196 KB
19.txt AC 1606 ms 77468 KB
20.txt AC 1737 ms 84384 KB
21.txt AC 1640 ms 78176 KB
22.txt AC 1604 ms 77488 KB
23.txt AC 904 ms 71036 KB
24.txt AC 1667 ms 76000 KB
25.txt AC 18 ms 3188 KB
26.txt AC 18 ms 3188 KB
s1.txt AC 18 ms 3188 KB
s2.txt AC 18 ms 3188 KB