| Task: | Company Queries II |
| Sender: | francden |
| Submission time: | 2025-10-13 15:43:20 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | RUNTIME ERROR | 0.07 s | details |
| #2 | RUNTIME ERROR | 0.06 s | details |
| #3 | RUNTIME ERROR | 0.06 s | details |
| #4 | RUNTIME ERROR | 0.07 s | details |
| #5 | RUNTIME ERROR | 0.07 s | details |
| #6 | RUNTIME ERROR | 0.16 s | details |
| #7 | RUNTIME ERROR | 0.13 s | details |
| #8 | RUNTIME ERROR | 0.16 s | details |
| #9 | RUNTIME ERROR | 0.16 s | details |
| #10 | RUNTIME ERROR | 0.16 s | details |
| #11 | RUNTIME ERROR | 0.07 s | details |
| #12 | RUNTIME ERROR | 0.16 s | details |
Code
import sys
sys.setrecursionlimit(300000)
input = sys.stdin.readline
n, q = map(int, input().split())
boss = [0] + [int(x) for x in input().split()]
# Build adjacency list
children = [[] for _ in range(n + 1)]
for i in range(2, n + 1):
children[boss[i]] .append(i)
# Euler tour and depth arrays
euler = []
depth = [0] * (n + 1)
first = [0] * (n + 1)
def dfs(u, d):
depth[u] = d
first[u] = len(euler)
euler.append(u)
for v in children[u]:
dfs(v, d + 1)
euler.append(u)
dfs(1, 0)
m = len(euler)
log = [0] * (m + 1)
for i in range(2, m + 1):
log[i] = log[i // 2] + 1
# Build Sparse Table
K = log[m] + 1
st = [[0] * m for _ in range(K)]
st[0] = euler.copy()
for k in range(1, K):
for i in range(m - (1 << k) + 1):
a = st[k - 1][i]
b = st[k - 1][i + (1 << (k - 1))]
st[k][i] = a if depth[a] < depth[b] else b
def lca(a, b):
i, j = first[a], first[b]
if i > j:
i, j = j, i
k = log[j - i + 1]
x = st[k][i]
y = st[k][j - (1 << k) + 1]
return x if depth[x] < depth[y] else y
# Answer queries
for _ in range(q):
a, b = map(int, input().split())
print(lca(a, b))
Test details
Test 1
Verdict: RUNTIME ERROR
| 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 |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 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 |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 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 |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 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 |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 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 |
|---|
| (empty) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 6
Verdict: RUNTIME ERROR
| 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) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 7
Verdict: RUNTIME ERROR
| 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) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 8
Verdict: RUNTIME ERROR
| 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) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 9
Verdict: RUNTIME ERROR
| 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) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 10
Verdict: RUNTIME ERROR
| 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) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 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 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of rangeTest 12
Verdict: RUNTIME ERROR
| 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) |
Error:
Traceback (most recent call last):
File "input/code.py", line 11, in <module>
children[boss[i]] .append(i)
IndexError: list index out of range