| Task: | Company Queries II |
| Sender: | azeaus1 |
| Submission time: | 2025-10-10 08:48:49 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.04 s | details |
| #2 | RUNTIME ERROR | 0.07 s | details |
| #3 | RUNTIME ERROR | 0.07 s | details |
| #4 | RUNTIME ERROR | 0.07 s | details |
| #5 | RUNTIME ERROR | 0.07 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | RUNTIME ERROR | 0.07 s | details |
| #12 | TIME LIMIT EXCEEDED | -- | details |
Code
import heapq
n, q = [int(x) for x in input().split()]
boss = [int(x) for x in input().split()]
queries = []
for _ in range(q):
a, b = [int(x) for x in input().split()]
queries.append([a-1, b-1])
treeFromDown = [0 for _ in range(n)]
treeFromUp = [[] for _ in range(n)]
for i in range(1, n):
treeFromDown[i] = boss[i-1]-1
treeFromUp[boss[i-1]-1].append(i)
def howManyLevelUp(x, y):
levelX = 0
xFound = False
levelY = 0
yFound = False
heap = [(0,0)]
while not xFound or not yFound:
node, level = heapq.heappop(heap)
if node == x:
levelX = level
xFound = True
elif node == y:
levelY = level
yFound = True
for child in treeFromUp[node]:
heapq.heappush(heap, (child, level+1))
return levelX, levelY
for query in queries:
a, b = query[0], query[1]
levelA, levelB = howManyLevelUp(a, b)
if levelA > levelB:
for _ in range(levelA-levelB):
b = treeFromDown[b]
elif levelB > levelA:
for _ in range(levelB-levelA):
a = treeFromDown[a]
while a != b:
a = treeFromDown[a]
b = treeFromDown[b]
print(a+1)Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10 10 1 2 3 4 5 6 7 8 9 6 9 8 10 10 3 ... |
| correct output |
|---|
| 6 8 3 1 8 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
Test 2
Verdict: RUNTIME ERROR
| input |
|---|
| 10 10 1 1 1 1 1 1 1 1 1 1 7 3 4 4 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
Error:
Traceback (most recent call last):
File "input/code.py", line 39, in <module>
levelA, levelB = howManyLevelUp(a, b)
File "input/code.py", line 24, in howManyLevelUp
node, level = heapq.heappop(heap)
File "/usr/lib/pypy3.8/heapq.py", line 137, in heappop
lastelt = heap.pop() # raises appropriate IndexError if heap is empty
IndexError: pop from empty listTest 3
Verdict: RUNTIME ERROR
| input |
|---|
| 10 10 1 1 1 1 2 3 4 4 1 1 8 2 7 8 3 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| 1 1 1 1 1 ... |
Error:
Traceback (most recent call last):
File "input/code.py", line 39, in <module>
levelA, levelB = howManyLevelUp(a, b)
File "input/code.py", line 24, in howManyLevelUp
node, level = heapq.heappop(heap)
File "/usr/lib/pypy3.8/heapq.py", line 137, in heappop
lastelt = heap.pop() # raises appropriate IndexError if heap is empty
IndexError: pop from empty listTest 4
Verdict: RUNTIME ERROR
| input |
|---|
| 10 10 1 1 3 1 2 2 5 3 9 7 2 7 6 3 9 ... |
| correct output |
|---|
| 2 2 3 1 1 ... |
| user output |
|---|
| 1 2 1 1 1 ... |
Error:
Traceback (most recent call last):
File "input/code.py", line 39, in <module>
levelA, levelB = howManyLevelUp(a, b)
File "input/code.py", line 24, in howManyLevelUp
node, level = heapq.heappop(heap)
File "/usr/lib/pypy3.8/heapq.py", line 137, in heappop
lastelt = heap.pop() # raises appropriate IndexError if heap is empty
IndexError: pop from empty listTest 5
Verdict: RUNTIME ERROR
| input |
|---|
| 10 10 1 2 3 2 5 3 2 2 4 6 1 1 3 1 9 ... |
| correct output |
|---|
| 1 1 1 2 2 ... |
| user output |
|---|
| 1 1 1 1 2 ... |
Error:
Traceback (most recent call last):
File "input/code.py", line 39, in <module>
levelA, levelB = howManyLevelUp(a, b)
File "input/code.py", line 24, in howManyLevelUp
node, level = heapq.heappop(heap)
File "/usr/lib/pypy3.8/heapq.py", line 137, in heappop
lastelt = heap.pop() # raises appropriate IndexError if heap is empty
IndexError: pop from empty listTest 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| correct output |
|---|
| 74862 8750 16237 72298 58111 ... |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1 1 1 1 1 ... |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 2 1 2 3 2 1 6 3 1 10 12 13 4... |
| correct output |
|---|
| 1 2 2 2 1 ... |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| correct output |
|---|
| 2796 633 633 151 2690 ... |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| correct output |
|---|
| 365 73 103 365 216 ... |
| user output |
|---|
| (empty) |
Test 11
Verdict: RUNTIME ERROR
| input |
|---|
| 2 4 1 1 1 1 2 2 1 ... |
| correct output |
|---|
| 1 1 1 2 |
| user output |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 39, in <module>
levelA, levelB = howManyLevelUp(a, b)
File "input/code.py", line 24, in howManyLevelUp
node, level = heapq.heappop(heap)
File "/usr/lib/pypy3.8/heapq.py", line 137, in heappop
lastelt = heap.pop() # raises appropriate IndexError if heap is empty
IndexError: pop from empty listTest 12
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 200000 200000 1 1 2 3 4 5 6 7 8 9 10 11 12 1... |
| correct output |
|---|
| 27468 6353 27468 6353 6353 ... |
| user output |
|---|
| (empty) |
