Task: | Distance Code |
Sender: | Jonathan Lööv |
Submission time: | 2019-03-06 12:28:33 +0200 |
Language: | Python3 |
Status: | READY |
Result: | 68 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 21 |
#2 | ACCEPTED | 47 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.06 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
#9 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
#10 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#11 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#12 | ACCEPTED | 0.05 s | 2, 3 | details |
#13 | ACCEPTED | 0.05 s | 2, 3 | details |
#14 | ACCEPTED | 0.05 s | 2, 3 | details |
#15 | ACCEPTED | 0.07 s | 2, 3 | details |
#16 | TIME LIMIT EXCEEDED | -- | 3 | details |
#17 | RUNTIME ERROR | 0.47 s | 3 | details |
#18 | TIME LIMIT EXCEEDED | -- | 3 | details |
#19 | TIME LIMIT EXCEEDED | -- | 3 | details |
#20 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
Code
def encode(): nnodes = int(input()) connections = {} for i in range(nnodes - 1): f, t = list(map(int, input().split())) if f in connections: connections[f].append(t) else: connections[f] = [t] if t in connections: connections[t].append(f) else: connections[t] = [f] root = 1 # The decoder will assume the root is not a leaf, but that doesn't matter when encoding # because the root won't matter for isometry dists = [] nodes = [] def pop_leafs(node, parent, depth, dist): for t in connections[node]: if t != parent: if dist == None: pop_leafs(t, node, depth + 1, None) else: pop_leafs(t, node, depth + 1, dist + 1) dist = 1 nodes.append(node) if dist != None: dists.append(dist) pop_leafs(root, 0, 0, None) print(" ".join(str(n) for n in nodes)) return dists def decode(): input() dists = list(map(int, input().split())) killed_nodes = {1} current_node = 1 max_node_idx = 1 connections_upwards = {} for dist in dists: connections_before = list(connections_upwards.keys()) # Go up one if current_node in connections_upwards: above = connections_upwards[current_node] else: # Create new node max_node_idx += 1 above = max_node_idx connections_upwards[current_node] = above down = above # Go down dist - 1 times for _ in range(dist - 1): # Create new node max_node_idx += 1 new = max_node_idx connections_upwards[new] = down down = new current_node = down killed_nodes.add(current_node) # print("After {} at {}".format(dist, current_node)) # print("Killed:", killed_nodes) # print("New connections:") # for f in connections_upwards: # if f not in connections_before: # print("\t", f, "->", connections_upwards[f]) # print() for f in connections_upwards: print(f, connections_upwards[f]) t = input() if t == "1": encode() else: decode()
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 2 2 1 |
correct output |
---|
(empty) |
user output |
---|
1 2 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 3 3 1 2 1 |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 4 3 2 2 1 4 1 |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 4 3 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 4 2 3 3 4 1 3 |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 2 4 |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 5 3 5 4 1 1 3 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 4 3 5 4 |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 5 3 2 3 4 5 1 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 4 3 5 3 |
Test 7
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 5 4 3 1 4 4 2 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 4 2 2 5 |
Test 8
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 9 3 8 9 2 9 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 4 2 5 2 6 2 ... |
Test 9
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 9 2 5 8 7 1 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 3 4 4 5 5 6 ... |
Test 10
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 10 4 9 1 4 7 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 4 3 5 2 6 5 ... |
Test 11
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 2 6 4 3 3 5 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 3 4 4 5 5 6 ... |
Test 12
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 10 6 6 255 6 428 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 4 2 5 2 6 2 ... Truncated |
Test 13
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 152 466 451 313 158 479 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 3 4 4 5 5 6 ... Truncated |
Test 14
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 109 440 330 190 443 161 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 4 3 5 4 6 4 ... Truncated |
Test 15
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 144 373 257 233 341 318 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 3 4 4 5 5 6 ... Truncated |
Test 16
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1 100000 54983 75172 93807 75172 44082 75172 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Test 17
Group: 3
Verdict: RUNTIME ERROR
input |
---|
1 100000 88863 19059 86423 76688 98536 95984 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 97, in <module> encode...
Test 18
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1 100000 59979 6389 19097 24999 27846 82330 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Test 19
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1 100000 58761 66001 25102 51081 98625 67861 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Test 20
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 6 2 1 3 2 4 2 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 3 2 2 4 5 4 4 6 |