| Task: | Company Queries II |
| Sender: | aalto26gh_015 |
| Submission time: | 2026-10-12 16:47:43 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.04 s | details |
| #2 | WRONG ANSWER | 0.04 s | details |
| #3 | ACCEPTED | 0.04 s | details |
| #4 | WRONG ANSWER | 0.04 s | details |
| #5 | WRONG ANSWER | 0.04 s | details |
| #6 | WRONG ANSWER | 0.47 s | details |
| #7 | ACCEPTED | 0.41 s | details |
| #8 | WRONG ANSWER | 0.55 s | details |
| #9 | WRONG ANSWER | 0.42 s | details |
| #10 | WRONG ANSWER | 0.41 s | details |
| #11 | WRONG ANSWER | 0.04 s | details |
| #12 | WRONG ANSWER | 0.46 s | details |
Code
import sys
input = sys.stdin.read().split()
n = int(input[0])
q = int(input[1])
log = 20
up = [([1]*log) for _ in range(n+1)]
depth = [0]*(n+1)
for i in range(2,n+1):
b = int(input[i])
up[i][0] = b
depth[i] = depth[b] + 1
for j in range(1,log):
up[i][j] = up[up[i][j-1]][j-1]
idx = n+1
for i in range(q):
a = int(input[idx])
b = int(input[idx+1])
if depth[a] < depth[b]:
a,b = b,a
diff = depth[a] - depth[b]
for j in range(log) :
if (diff >> j) & 1:
a = up[a][j]
if a ==b :
print(a)
continue
for j in range(log -1, -1, -1):
if up[a][j] != up[b][j]:
a = up[a][j]
b = up[b][j]
print(up[a][0])
idx +=2Test 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 |
|---|
| 6 6 6 6 6 ... |
Feedback: Incorrect character on line 2 col 1: expected "8", got "6"
Test 2
Verdict: WRONG ANSWER
| 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 ... |
Feedback: Incorrect character on line 7 col 1: expected "4", got "1"
Test 3
Verdict: ACCEPTED
| 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 ... |
Test 4
Verdict: WRONG ANSWER
| 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 |
|---|
| 2 2 2 2 2 ... |
Feedback: Incorrect character on line 3 col 1: expected "3", got "2"
Test 5
Verdict: WRONG ANSWER
| 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 1 ... |
Feedback: Incorrect character on line 4 col 1: expected "2", got "1"
Test 6
Verdict: WRONG ANSWER
| 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 |
|---|
| 74862 74862 74862 74862 74862 ... |
Feedback: Incorrect character on line 2 col 1: expected "8750", got "74862"
Test 7
Verdict: ACCEPTED
| 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 |
|---|
| 1 1 1 1 1 ... |
Test 8
Verdict: WRONG ANSWER
| 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 |
|---|
| 1 2 2 2 1 ... |
Feedback: Incorrect character on line 58835 col 1: expected "3", got "8579"
Test 9
Verdict: WRONG ANSWER
| 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 |
|---|
| 2796 633 633 151 2690 ... |
Feedback: Incorrect character on line 19 col 1: expected "2796", got "121036"
Test 10
Verdict: WRONG ANSWER
| 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 |
|---|
| 365 73 103 365 216 ... |
Feedback: Incorrect character on line 118 col 1: expected "103", got "5249"
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 2 4 1 1 1 1 2 2 1 ... |
| correct output |
|---|
| 1 1 1 2 |
| user output |
|---|
| 1 1 1 1 |
Feedback: Incorrect character on line 4 col 1: expected "2", got "1"
Test 12
Verdict: WRONG ANSWER
| 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 |
|---|
| 27468 6353 27468 6353 6353 ... |
Feedback: Incorrect character on line 9 col 1: expected "27468", got "130189"
