CSES - NOI 2019 - Results
Submission details
Task:Distance Code
Sender:Loke Gustafsson
Submission time:2019-03-06 15:42:25 +0200
Language:Python3
Status:READY
Result:68
Feedback
groupverdictscore
#1ACCEPTED21
#2ACCEPTED47
#30
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1, 2, 3details
#2ACCEPTED0.04 s1, 2, 3details
#3ACCEPTED0.04 s1, 2, 3details
#4ACCEPTED0.04 s1, 2, 3details
#5ACCEPTED0.05 s1, 2, 3details
#6ACCEPTED0.05 s1, 2, 3details
#7ACCEPTED0.04 s1, 2, 3details
#8ACCEPTED0.04 s1, 2, 3details
#9ACCEPTED0.05 s1, 2, 3details
#10ACCEPTED0.04 s1, 2, 3details
#11ACCEPTED0.04 s1, 2, 3details
#12ACCEPTED0.05 s2, 3details
#13ACCEPTED0.06 s2, 3details
#14ACCEPTED0.05 s2, 3details
#15ACCEPTED0.05 s2, 3details
#16--3details
#170.51 s3details
#18--3details
#19--3details
#20ACCEPTED0.05 s1, 2, 3details

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
...

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
...

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
...

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
...

Test 16

Group: 3

Verdict:

input
1
100000
54983 75172
93807 75172
44082 75172
...

correct output
(empty)

user output
(empty)

Test 17

Group: 3

Verdict:

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 = makeNode(1, None, graph)
  File "input/code.py", line 27, in makeNode
    n.children.append(makeNode(p, n, graph))
  File "input/code.py", line 27, in makeNode
    n.children.append(makeNode(p, n, graph))
  File "input/code.py", line 27, in makeNode
    n.children.append(makeNode(p, n, graph))
  [Previous line repeated 991 more times]
  File "input/code.py", line 22, in makeNode
    n = Node(i, par)
  File "input/code.py", line 8, in __init__
    self.children = list()
RecursionError: maximum recursion depth exceeded while calling a Python object

Test 18

Group: 3

Verdict:

input
1
100000
59979 6389
19097 24999
27846 82330
...

correct output
(empty)

user output
(empty)

Test 19

Group: 3

Verdict:

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