Task: | Company Queries II |
Sender: | Nallue |
Submission time: | 2024-10-19 13:54:05 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.00 s | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | WRONG ANSWER | 0.00 s | details |
#4 | WRONG ANSWER | 0.01 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.76 s | details |
#7 | ACCEPTED | 0.69 s | details |
#8 | WRONG ANSWER | 0.73 s | details |
#9 | WRONG ANSWER | 0.74 s | details |
#10 | WRONG ANSWER | 0.75 s | details |
#11 | WRONG ANSWER | 0.00 s | details |
#12 | WRONG ANSWER | 0.74 s | details |
Compiler report
input/code.cpp: In member function 'int TreeAncestor::getKthAncestor(int, int)': input/code.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 30 | for (int j = 0; j < up[0].size(); j++) { | ~~^~~~~~~~~~~~~~
Code
#include <iostream>#include <vector>#include <cmath>using namespace std;class TreeAncestor {public:int n;vector<vector<int>> up;TreeAncestor(int n, vector<int>& parent) : n(n) {int maxLog = log2(n) + 1;up.assign(n, vector<int>(maxLog, -1));for (int i = 0; i < n; i++) {up[i][0] = parent[i];}for (int j = 1; j < maxLog; j++) {for (int i = 0; i < n; i++) {if (up[i][j - 1] != -1) {up[i][j] = up[up[i][j - 1]][j - 1];}}}}int getKthAncestor(int node, int k) {for (int j = 0; j < up[0].size(); j++) {if (k & (1 << j)) {node = up[node][j];if (node == -1) return -1;}}return node;}};int main() {int n,q; // Número de nodos en el árbol (1-indexado, pero usamos 0-indexado en el código)cin >> n >> q;// El nodo 0 es una raíz ficticia, y los nodos 1-8 tienen la estructura según el ejemplovector<int> parent(n,-1);for(int i=1; i<n; i++){int temp;cin >> temp;parent[i] = temp-1;}TreeAncestor treeAncestor(n, parent);for(int i=0; i<q; i++){int a,b;cin >> a >> b;a -=1;b -=1;vector<bool> jefe(n,false);int count=1;int comm;if(a==0 or b==0){cout << 1 << endl;continue;}while(true){int jef1 = treeAncestor.getKthAncestor(a, count);int jef2 = treeAncestor.getKthAncestor(b, count);if(jefe[jef1]){comm = jef1+1;break;}else jefe[jef1]=true;if(jefe[jef2]){comm = jef2+1;break;}else jefe[jef2]=true;}cout << comm <<endl;}}
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 9 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: WRONG ANSWER
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 4 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 1 3 9 ... |
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 |
---|
167533 8749 16236 90860 102869 ... 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 |
---|
57441 39658 18686 770 9087 ... 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 |
---|
33593 181356 4231 126193 78223 ... 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 |
---|
72601 48542 1630 51761 50395 ... 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 |
---|
31654 133728 131947 43679 16241 ... Truncated |