Submission #2529924


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 C - Reconciled?
User nadare881
Language PyPy3 (2.4.0)
Score 0
Code Size 876 Byte
Status RE
Exec Time 172 ms
Memory 38768 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
RE × 4
RE × 16
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.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, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt RE 172 ms 38768 KB
02.txt RE 164 ms 38256 KB
03.txt RE 162 ms 38256 KB
04.txt RE 161 ms 38256 KB
05.txt RE 167 ms 38256 KB
06.txt RE 162 ms 38256 KB
07.txt RE 165 ms 38256 KB
08.txt RE 170 ms 38256 KB
09.txt RE 163 ms 38256 KB
10.txt RE 163 ms 38256 KB
11.txt RE 162 ms 38256 KB
12.txt RE 160 ms 38384 KB
s1.txt RE 166 ms 38256 KB
s2.txt RE 162 ms 38256 KB
s3.txt RE 162 ms 38256 KB
s4.txt RE 161 ms 38256 KB