Task: | Distance Code |
Sender: | Loke Gustafsson |
Submission time: | 2019-03-06 15:42:25 +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.05 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.04 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.04 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.06 s | 2, 3 | details |
#14 | ACCEPTED | 0.05 s | 2, 3 | details |
#15 | ACCEPTED | 0.05 s | 2, 3 | details |
#16 | TIME LIMIT EXCEEDED | -- | 3 | details |
#17 | RUNTIME ERROR | 0.51 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
import sys class Node: def __init__(self, i, par): self.parent = par self.id = i self.nextChild = 0 self.children = list() def isLeaf(self): return self.nextChild >= len(self.children) def next(self): if self.isLeaf(): return self.parent else: temp = self.children[self.nextChild] self.nextChild += 1 return temp def makeNode(i, par, graph): n = Node(i, par) for p in graph[i]: if par != None and p == par.id: continue n.children.append(makeNode(p, n, graph)) return n def printEdges(node): for child in node.children: print(child.id, node.id) printEdges(child) t = int(input()) n = int(input()) if (t == 1): # ENCODE graph = dict() for i in range(n-1): k = input() a, b = list(map(int, k.split(' '))) if not a in graph: graph[a] = list() if not b in graph: graph[b] = list() graph[a].append(b) graph[b].append(a) tree = makeNode(1, None, graph) active = tree; while not active.isLeaf(): active = active.next() for i in range(n): sys.stdout.write(str(active.id) + " ") active = active.next() if active == None: break while not active.isLeaf(): active = active.next() else: # DECODE idn = 1; active = Node(idn, None) idn += 1; for i in map(int, input().split(' ')): if (active.parent == None): active.parent = Node(idn, None) idn += 1 active.parent.children.append(active) active = active.parent while i > 1: # move down as well child = Node(idn, active) active.children.append(child) active = child idn += 1 i -= 1 printEdges(active)
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 |
---|
2 3 1 2 4 3 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 4 2 3 3 4 1 3 |
correct output |
---|
(empty) |
user output |
---|
2 4 1 2 3 2 |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 5 3 5 4 1 1 3 ... |
correct output |
---|
(empty) |
user output |
---|
2 3 1 2 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 |
---|
2 5 1 2 3 2 4 2 |
Test 8
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 9 3 8 9 2 9 ... |
correct output |
---|
(empty) |
user output |
---|
2 10 1 2 3 2 4 2 5 2 ... |
Test 9
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 9 2 5 8 7 1 ... |
correct output |
---|
(empty) |
user output |
---|
6 7 5 6 4 5 3 4 2 3 ... |
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 |
---|
5 6 4 5 3 4 2 3 1 2 ... |
Test 12
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 10 6 6 255 6 428 ... |
correct output |
---|
(empty) |
user output |
---|
2 500 1 2 3 2 4 2 5 2 ... Truncated |
Test 13
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 152 466 451 313 158 479 ... |
correct output |
---|
(empty) |
user output |
---|
350 351 349 350 348 349 347 348 346 347 ... 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 |
---|
6 7 5 6 4 5 3 4 2 3 ... 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 52, in <module> tree =...
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 |
---|
4 6 2 4 1 2 3 2 5 4 |