Submission #2529925
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 | PyPy3 (2.4.0) |
Score | 500 |
Code Size | 876 Byte |
Status | AC |
Exec Time | 1615 ms |
Memory | 127960 KB |
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 | 1529 ms | 125656 KB |
02.txt | AC | 1474 ms | 127064 KB |
03.txt | AC | 1512 ms | 126680 KB |
04.txt | AC | 1571 ms | 126296 KB |
05.txt | AC | 1573 ms | 120664 KB |
06.txt | AC | 1615 ms | 123992 KB |
07.txt | AC | 1539 ms | 123096 KB |
08.txt | AC | 1546 ms | 123608 KB |
09.txt | AC | 1519 ms | 127832 KB |
10.txt | AC | 1496 ms | 127960 KB |
11.txt | AC | 1464 ms | 127468 KB |
12.txt | AC | 1455 ms | 127448 KB |
13.txt | AC | 1268 ms | 126168 KB |
14.txt | AC | 1352 ms | 125144 KB |
15.txt | AC | 1219 ms | 124248 KB |
16.txt | AC | 1272 ms | 120792 KB |
17.txt | AC | 1344 ms | 127928 KB |
18.txt | AC | 1238 ms | 126168 KB |
19.txt | AC | 1284 ms | 127192 KB |
20.txt | AC | 1344 ms | 127704 KB |
21.txt | AC | 1351 ms | 125400 KB |
22.txt | AC | 1308 ms | 127320 KB |
23.txt | AC | 728 ms | 117848 KB |
24.txt | AC | 1386 ms | 123864 KB |
25.txt | AC | 171 ms | 38256 KB |
26.txt | AC | 169 ms | 38256 KB |
s1.txt | AC | 174 ms | 38256 KB |
s2.txt | AC | 168 ms | 38256 KB |