Task: | Company Queries II |
Sender: | esya_rae |
Submission time: | 2024-10-23 21:41:53 +0300 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | RUNTIME ERROR | 0.08 s | details |
#2 | RUNTIME ERROR | 0.08 s | details |
#3 | RUNTIME ERROR | 0.08 s | details |
#4 | RUNTIME ERROR | 0.08 s | details |
#5 | RUNTIME ERROR | 0.08 s | details |
#6 | RUNTIME ERROR | 0.98 s | details |
#7 | RUNTIME ERROR | 0.16 s | details |
#8 | RUNTIME ERROR | 0.19 s | details |
#9 | RUNTIME ERROR | 0.20 s | details |
#10 | RUNTIME ERROR | 0.20 s | details |
#11 | RUNTIME ERROR | 0.08 s | details |
#12 | RUNTIME ERROR | 0.24 s | details |
Code
import math import sys sys.setrecursionlimit(10**6) def dfs(v, d): global g, node_ids, depths, r node_ids.append(v) depths.append(d) r[v] = len(node_ids)-1 for w in g[v]: dfs(w, d + 1) node_ids.append(v) depths.append(d) visited[v] = True def build_tree_min(i): global depths, min_tree, k, m if i >= k + m: return math.inf, -1 if i >= k: min_tree[i] = (depths[i - k], i - k) return min_tree[i] d1, i1 = build_tree_min(2 * i) d2, i2 = build_tree_min(2 * i + 1) if d1 < d2: min_tree[i] = (d1, i1) else: min_tree[i] = (d2, i2) return min_tree[i] def answer_min(a, b): global min_tree, k res = math.inf value = -1 a += k b += k while a <= b: if a % 2 == 1: z, v = min_tree[a] if res > z: value = v res = z a += 1 if b % 2 == 0: z, v = min_tree[b] if res > z: value = v res = z b -= 1 a //= 2 b //= 2 return res, value n, q = map(int, input().split()) node_ids = [] depths = [] g = [[] for _ in range(n)] r = [-1] * n x = list(map(int, input().split())) for i in range(n - 1): g[x[i] - 1].append(i + 1) dfs(0, 0) m = len(node_ids) k = 2 ** math.ceil(math.log(m, 2)) min_tree = [math.inf] * (2 * k) build_tree_min(1) # print(k, min_tree) output = [] for i in range(q): a, b = map(int, input().split()) a -= 1 b -= 1 v, w = answer_min(min(r[a], r[b]), max(r[a], r[b])) output.append(str(node_ids[w] + 1)) sys.stdout.write("\n".join(output) + "\n")
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 66, in <module> dfs(0,...
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 |
---|
(empty) |
Error:
Traceback (most recent call last): File "input/code.py", line 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...
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 66, in <module> dfs(0,...
Test 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 66, in <module> dfs(0,...