Task: | Company Queries II |
Sender: | Niilo |
Submission time: | 2024-10-10 17:06:29 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | details |
#2 | WRONG ANSWER | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | WRONG ANSWER | 0.01 s | details |
#5 | WRONG ANSWER | 0.01 s | details |
#6 | WRONG ANSWER | 0.72 s | details |
#7 | ACCEPTED | 0.58 s | details |
#8 | WRONG ANSWER | 0.67 s | details |
#9 | WRONG ANSWER | 0.74 s | details |
#10 | WRONG ANSWER | 0.70 s | details |
#11 | WRONG ANSWER | 0.01 s | details |
#12 | WRONG ANSWER | 0.75 s | details |
Code
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 18; vector<int> V[1<<N]; int D[1<<N]; int T[N][1<<N]; int fp(int i, int s) { for (int j = 0; j < N; ++j) { if (s&(1<<j)) { i = T[j][i]; } } return i; } int fca(int a, int b) { if (D[a] < D[b]) swap(a,b); a = fp(a, D[a] - D[b]); for (int j = N-1; j >= 0; --j) { if (T[j][a] != T[j][b]) { a = T[j][a]; b = T[j][b]; } } return T[0][a]; } void dfs(int i, int p, int d) { D[i] = d; T[0][i] = p; for (int j : V[i]) { if (j != p) dfs(j,i,d+1); } } int main() { int n, q; cin >> n >> q; for (int i = 1; i < n; ++i) { int a; cin >> a; V[a-1].push_back(i); V[i].push_back(a-1); } dfs(0,0,0); for (int i = 1; i < N; ++i) { for (int j = 0; j < n; ++j) { T[i][j] = T[i-1][T[i-1][j]]; } } for (int i = 0; i < q; ++i) { int a, b; cin >> a >> b; cout << fca(a-1, b-1) + 1 << '\n'; } }
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 |
---|
5 7 2 1 7 ... |
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 ... |
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 |
---|
1 2 1 1 1 ... |
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 2 2 ... |
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 |
---|
74861 8749 16236 72297 58110 ... Truncated |
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 ... Truncated |
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 ... Truncated |
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 ... Truncated |
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 ... Truncated |
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 |
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 ... Truncated |