Task: | Distance Code |
Sender: | Gamithra Marga |
Submission time: | 2019-03-06 13:35:15 +0200 |
Language: | Python3 |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 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.05 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.05 s | 1, 2, 3 | details |
#8 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#9 | ACCEPTED | 0.04 s | 1, 2, 3 | details |
#10 | WRONG ANSWER | 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.34 s | 2, 3 | details |
#14 | WRONG ANSWER | 0.06 s | 2, 3 | details |
#15 | WRONG ANSWER | 0.05 s | 2, 3 | details |
#16 | TIME LIMIT EXCEEDED | -- | 3 | details |
#17 | TIME LIMIT EXCEEDED | -- | 3 | details |
#18 | TIME LIMIT EXCEEDED | -- | 3 | details |
#19 | TIME LIMIT EXCEEDED | -- | 3 | details |
#20 | ACCEPTED | 0.05 s | 1, 2, 3 | details |
Code
#!/usr/bin/python3 import sys do = int(sys.stdin.readline()) n = int(sys.stdin.readline()) graph = {} visited = [] cur_ans = -1 found = False def findParent(cur_node, left_to_walk): global found, cur_ans #print("now checking node", cur_node, "left to walk", left_to_walk, found) if not found: visited.append(cur_node) if left_to_walk == 1: if len(graph[cur_node])<3: #print("node has space", len(graph[cur_node])) if cur_node == 1 and len(graph[cur_node]) > 1: return else: cur_ans = cur_node found = True return else: return else: children = graph[cur_node] for c in children: if c not in visited: return findParent(c, left_to_walk -1) else: return if do == 1: edges = {} cur = [[] for i in range(0, n+1)] left = [i for i in range(1, n+1)] removed = [] root_node = -1 for i in range(n-1): a, b = [int(x) for x in sys.stdin.readline().split(" ")] if a not in edges: edges[a] = [] if b not in edges: edges[b] = [] edges[a].append(b) edges[b].append(a) cur[a].append(b) cur[b].append(a) if n == 2: print("2 1") sys.exit() for node in range(1, n+1): if len(cur[node]) == 2: root_node = node break # left to add condition for when is just 2 nodes while len(left) > 1: for i in range(1, n+1): if len(cur[i]) == 1 and i != root_node: cur[cur[i][0]].remove(i) removed.append(i) left.remove(i) cur[i] = [] removed.append(left[0]) print(" ".join([str(x) for x in removed])) elif do == 2: code = [int(x) for x in sys.stdin.readline().split(" ")] code.reverse() if n == 2: print("2 1") sys.exit() #edges = {} #graph = [[] for i in range(0, n+1)] placed = [1, 2] graph[1] = [2] graph[2] = [1] last = 2 left = [i for i in range(3, n+1)] for i in range(3, n+1): to_walk = code[i-2] #find a parent visited = [] found = False findParent(last, to_walk) a = cur_ans if i not in graph: graph[i] = [] graph[i].append(a) graph[a].append(i) placed.append(i) last = i done = [] for i in range(1, n+1): for c in graph[i]: if c not in done: print(i, c) done.append(i) #print(graph) sys.exit()
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 2 2 1 |
correct output |
---|
(empty) |
user output |
---|
2 1 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 3 3 1 2 1 |
correct output |
---|
(empty) |
user output |
---|
1 2 1 3 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 4 3 2 2 1 4 1 |
correct output |
---|
(empty) |
user output |
---|
1 2 1 3 2 4 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 4 2 3 3 4 1 3 |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 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 1 4 2 3 4 5 |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 5 3 2 3 4 5 1 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 1 3 2 4 2 5 |
Test 7
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 5 4 3 1 4 4 2 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 2 4 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 2 3 2 4 2 5 2 6 ... |
Test 9
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 9 2 5 8 7 1 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 1 5 2 3 3 4 4 6 ... |
Test 10
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 10 10 4 9 1 4 7 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 2 3 3 4 3 7 3 8 ... |
Test 11
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 10 2 6 4 3 3 5 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 1 3 2 5 2 9 3 4 ... |
Test 12
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 10 6 6 255 6 428 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 1 3 1 4 1 5 1 6 ... Truncated |
Test 13
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1 500 152 466 451 313 158 479 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 1 214 2 3 3 4 4 5 ... Truncated |
Test 14
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
1 500 109 440 330 190 443 161 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 1 21 2 3 2 35 3 4 ... Truncated |
Test 15
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
1 500 144 373 257 233 341 318 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 1 227 2 3 2 326 2 327 ... 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: TIME LIMIT EXCEEDED
input |
---|
1 100000 88863 19059 86423 76688 98536 95984 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
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 1 3 1 4 2 5 2 6 |