QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620025 | #5015. 树 | HJY2022 | 0 | 12ms | 8140kb | C++14 | 1.8kb | 2024-10-07 16:20:38 | 2024-10-07 16:20:42 |
Judging History
answer
#include "tree.h"
#include<bits/stdc++.h>
using namespace std;
const int MX = 1005;
vector<int > c[MX];int dep[MX];
vector<int > g[MX];int fa[MX][11];
void init(int x,int f){
fa[x][0] = f;
for(int i = 1;i <= 10;i++)fa[x][i] = fa[fa[x][i - 1]][i - 1];
}
int lca(int x,int y){
if(dep[x] < dep[y])swap(x,y);
for(int i = 10;i >= 0;i--)if(dep[fa[x][i]] >= dep[y])x = fa[x][i];
if(x == y)return x;
for(int i = 10;i >= 0;i--)if(fa[x][i] != fa[y][i])x = fa[x][i],y = fa[y][i];
return fa[x][0];
}
int dist(int x,int y){
int lc = lca(x,y);
return dep[x] + dep[y] - 2 * dep[lc];
}
void solve(vector<int > A,vector<int > B){
/*
cerr << "solve : \n";
cerr << "A = ";
for(auto it : A)cerr << it << ' ';
cerr << '\n';
cerr << "B = ";
for(auto it : B)cerr << it << ' ';
cerr << '\n';
*/
if(A.size() == 1){
for(auto it : B){answer(it,A[0]);init(it,A[0]);}
return;
}
if(B.size() == 0)return;
int p = A.size() / 2;vector<int > LA,RA,LB,RB;
for(int i = 0;i < p;i++)LA.push_back(A[i]);
for(int i = p;i < A.size();i++)RA.push_back(A[i]);
set<int > s;
for(auto it : LA){
int sum = 0;
for(auto jt : LA)sum += dist(it,jt);
s.insert(sum);
}
int num = LA.size();
for(auto it : B){
int cur = ask(it,LA);
if(s.find(cur - num) != s.end())LB.push_back(it);
else RB.push_back(it);
}
solve(LA,LB);solve(RA,RB);
}
void solver(int n,int A,int B){
vector<int > tmp;tmp.push_back(1);
int mx = 0;c[0].push_back(1);
for(int i = 2;i <= n;i++){
dep[i] = ask(i,tmp);
c[dep[i]].push_back(i);
mx = max(mx,dep[i]);
}
init(1,1);
for(int i = 0;i < mx;i++){
/*
cerr << "solve Layer : \n";
for(auto it : c[i])cerr << it << ' ';
cerr << '\n';
for(auto it : c[i + 1])cerr << it << ' ';
cerr << '\n';
*/
solve(c[i],c[i + 1]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 7956kb
input:
1000 500000 500000 1 2 2 3 2 4 2 5 2 6 3 7 2 8 5 9 5 10 9 11 2 12 9 13 4 14 5 15 12 16 5 17 4 18 4 19 13 20 9 21 19 22 7 23 6 24 14 25 2 26 10 27 14 28 21 29 17 30 8 31 15 32 9 33 22 34 24 35 20 36 6 37 12 38 19 39 31 40 35 41 25 42 11 43 8 44 9 45 12 46 26 47 10 48 6 49 27 50 39 51 33 52 6 53 43 54...
output:
Different tree
result:
wrong answer Wrong Answer
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 17
Accepted
time: 1ms
memory: 4140kb
input:
100 3000 40000 66 95 66 60 66 93 66 69 66 82 66 24 66 64 66 84 66 42 66 22 66 67 66 54 66 90 66 26 66 41 66 18 66 43 66 68 66 36 66 88 66 33 66 29 66 79 66 6 66 48 66 47 66 8 66 38 66 61 69 97 64 30 38 86 88 14 18 10 54 81 88 25 29 2 18 21 95 46 42 80 93 91 61 62 68 35 47 23 69 17 93 28 18 31 61 70 ...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #12:
score: 17
Accepted
time: 1ms
memory: 4100kb
input:
100 3000 40000 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 26 53...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #13:
score: 17
Accepted
time: 1ms
memory: 4180kb
input:
100 3000 40000 1 2 2 3 3 4 3 5 5 6 6 7 4 8 7 9 1 10 4 11 3 12 7 13 1 14 1 15 7 16 3 17 4 18 7 19 9 20 1 21 8 22 10 23 6 24 6 25 2 26 10 27 7 28 5 29 5 30 8 31 4 32 4 33 10 34 2 35 8 36 9 37 3 38 6 39 3 40 8 41 9 42 6 43 10 44 8 45 5 46 8 47 8 48 2 49 8 50 8 51 3 52 1 53 3 54 5 55 5 56 8 57 3 58 10 5...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #14:
score: 17
Accepted
time: 1ms
memory: 4232kb
input:
100 3000 40000 13 50 17 13 62 17 5 62 74 5 83 74 98 83 37 98 80 37 23 80 87 23 27 87 40 27 95 40 52 95 54 52 67 54 42 67 18 42 34 18 81 34 59 81 12 59 30 12 64 30 15 64 92 15 61 92 1 61 72 1 16 72 3 16 48 3 31 48 41 31 77 41 93 77 33 93 96 33 53 96 28 53 90 28 25 90 26 25 57 55 85 57 45 85 20 45 22 ...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #15:
score: 17
Accepted
time: 1ms
memory: 4460kb
input:
100 3000 40000 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 26 53...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #16:
score: 17
Accepted
time: 1ms
memory: 4064kb
input:
100 3000 40000 1 2 2 3 3 4 3 5 5 6 6 7 6 8 8 9 9 10 10 11 10 12 12 13 12 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 21 23 23 24 24 25 25 26 25 27 26 28 28 29 28 30 30 31 30 32 32 33 33 34 33 35 35 36 36 37 36 38 38 39 39 40 39 41 41 42 41 43 42 44 43 45 44 46 46 47 47 48 48 49 48 50 49 51 50...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #17:
score: 17
Accepted
time: 1ms
memory: 4176kb
input:
100 3000 40000 1 2 1 3 1 4 2 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 2 14 1 15 1 16 2 17 2 18 2 19 1 20 2 21 2 22 2 23 1 24 2 25 2 26 2 27 2 28 2 29 1 30 1 31 2 32 2 33 1 34 1 35 1 36 1 37 2 38 2 39 2 40 1 41 2 42 2 43 1 44 2 45 2 46 2 47 2 48 1 49 2 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 2 6...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #18:
score: 17
Accepted
time: 1ms
memory: 4164kb
input:
100 3000 40000 1 2 2 3 3 4 4 5 2 6 1 7 7 8 7 9 1 10 4 11 7 12 1 13 5 14 5 15 4 16 7 17 9 18 5 19 10 20 8 21 1 22 1 23 6 24 5 25 2 26 7 27 1 28 7 29 9 30 10 31 7 32 3 33 8 34 10 35 8 36 10 37 2 38 7 39 6 40 9 41 8 42 7 43 9 44 3 45 2 46 5 47 10 48 2 49 6 50 4 51 6 52 5 53 8 54 5 55 6 56 6 57 7 58 3 5...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #19:
score: 17
Accepted
time: 1ms
memory: 4192kb
input:
100 3000 40000 1 2 1 3 3 4 3 5 5 6 5 7 6 8 7 9 8 10 10 11 10 12 12 13 13 14 13 15 15 16 16 17 16 18 17 19 18 20 19 21 21 22 22 23 23 24 24 25 24 26 25 27 26 28 27 29 28 30 30 31 30 32 31 33 33 34 34 35 34 36 35 37 37 38 38 39 39 40 39 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 48 50 49 51 50...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #20:
score: 17
Accepted
time: 0ms
memory: 4236kb
input:
100 3000 40000 1 2 1 3 1 4 1 5 2 6 2 7 2 8 3 9 3 10 3 11 4 12 4 13 4 14 5 15 5 16 5 17 6 18 6 19 6 20 7 21 7 22 7 23 8 24 8 25 8 26 9 27 9 28 9 29 10 30 10 31 10 32 11 33 11 34 11 35 12 36 12 37 12 38 13 39 13 40 13 41 14 42 14 43 14 44 15 45 15 46 15 47 16 48 16 49 16 50 17 51 17 52 17 53 18 54 18 ...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #21:
score: 17
Accepted
time: 1ms
memory: 4136kb
input:
100 3000 40000 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 26 53...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #22:
score: 17
Accepted
time: 0ms
memory: 4452kb
input:
100 3000 40000 1 2 1 3 1 4 1 5 2 6 3 7 1 8 3 9 4 10 3 11 8 12 3 13 1 14 6 15 1 16 2 17 9 18 5 19 6 20 20 21 8 22 9 23 10 24 7 25 4 26 19 27 24 28 4 29 5 30 19 31 6 32 26 33 23 34 17 35 10 36 28 37 15 38 18 39 26 40 33 41 38 42 41 43 34 44 18 45 12 46 33 47 34 48 25 49 27 50 10 51 21 52 29 53 4 54 30...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #23:
score: 17
Accepted
time: 1ms
memory: 4452kb
input:
100 3000 40000 1 2 1 3 1 4 1 5 3 6 1 7 1 8 5 9 2 10 6 11 3 12 9 13 7 14 12 15 8 16 9 17 11 18 13 19 17 20 19 21 18 22 20 23 14 24 18 25 24 26 25 27 24 28 21 29 20 30 22 31 26 32 23 33 24 34 26 35 32 36 28 37 36 38 34 39 34 40 35 41 32 42 34 43 41 44 43 45 43 46 41 47 38 48 43 49 42 50 42 51 49 52 48...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #24:
score: 17
Accepted
time: 0ms
memory: 4176kb
input:
100 3000 40000 1 2 2 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 2 11 2 12 1 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 1 21 1 22 1 23 2 24 1 25 1 26 2 27 2 28 2 29 2 30 1 31 1 32 1 33 2 34 1 35 2 36 2 37 1 38 1 39 2 40 2 41 2 42 1 43 2 44 1 45 2 46 1 47 2 48 2 49 2 50 2 51 1 52 1 53 1 54 1 55 2 56 1 57 2 58 2 59 1 6...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #25:
score: 0
Wrong Answer
time: 1ms
memory: 6204kb
input:
100 3000 40000 1 2 2 3 3 4 4 5 2 6 1 7 7 8 1 9 2 10 3 11 4 12 9 13 3 14 1 15 7 16 5 17 10 18 7 19 6 20 4 21 2 22 8 23 7 24 4 25 2 26 5 27 6 28 3 29 4 30 7 31 10 32 7 33 5 34 10 35 5 36 8 37 7 38 3 39 6 40 3 41 4 42 5 43 7 44 10 45 8 46 9 47 4 48 2 49 4 50 2 51 3 52 5 53 6 54 3 55 10 56 1 57 5 58 7 5...
output:
Different tree
result:
wrong answer Wrong Answer
Subtask #3:
score: 0
Wrong Answer
Test #111:
score: 20
Accepted
time: 7ms
memory: 7872kb
input:
1000 50000 3000000 126 207 937 126 615 937 837 615 500 837 588 500 505 588 353 505 60 353 904 60 656 904 685 656 460 685 614 460 551 614 537 551 858 537 596 858 9 596 738 9 918 738 322 918 940 322 859 940 113 859 110 113 312 110 995 312 443 995 246 443 257 246 238 257 999 238 885 999 976 885 330 976...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #112:
score: 20
Accepted
time: 5ms
memory: 7844kb
input:
1000 50000 3000000 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 2...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #113:
score: 20
Accepted
time: 9ms
memory: 7876kb
input:
1000 50000 3000000 1 2 2 3 2 4 4 5 5 6 6 7 6 8 8 9 8 10 10 11 10 12 12 13 12 14 13 15 14 16 15 17 16 18 18 19 18 20 19 21 20 22 21 23 22 24 24 25 24 26 26 27 27 28 27 29 28 30 29 31 30 32 31 33 32 34 34 35 35 36 36 37 36 38 37 39 39 40 39 41 41 42 41 43 42 44 43 45 45 46 45 47 47 48 48 49 48 50 50 5...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #114:
score: 20
Accepted
time: 4ms
memory: 7872kb
input:
1000 50000 3000000 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 2...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #115:
score: 20
Accepted
time: 12ms
memory: 8140kb
input:
1000 50000 3000000 31 688 31 684 31 63 31 564 31 34 31 288 31 808 31 356 31 327 31 458 31 993 31 344 31 902 31 407 31 37 31 150 31 969 31 323 31 790 31 464 31 230 31 999 31 936 31 106 31 965 31 771 31 663 31 476 31 652 31 991 31 475 31 258 31 395 31 664 31 762 31 934 31 951 31 419 31 84 31 70 31 167...
output:
areawavesuitbannerresortfatplasterdeclarationthesearejustrandomwords
result:
ok Orz..Orz..Orz..Orz..Orz
Test #116:
score: 0
Wrong Answer
time: 12ms
memory: 7956kb
input:
1000 50000 3000000 740 869 740 437 740 881 740 650 740 319 740 195 740 613 740 606 740 243 740 406 740 669 740 146 740 183 740 999 740 651 740 176 740 97 740 908 740 750 740 609 740 639 740 681 740 755 740 354 740 993 740 334 740 926 740 904 740 184 740 301 740 271 740 859 740 622 740 198 740 716 74...
output:
Different tree
result:
wrong answer Wrong Answer
Subtask #4:
score: 0
Wrong Answer
Test #211:
score: 0
Wrong Answer
time: 6ms
memory: 8136kb
input:
990 8500 300000 1 2 1 3 1 4 1 5 2 6 2 7 2 8 3 9 3 10 3 11 4 12 4 13 4 14 5 15 5 16 5 17 6 18 6 19 6 20 7 21 7 22 7 23 8 24 8 25 8 26 9 27 9 28 9 29 10 30 10 31 10 32 11 33 11 34 11 35 12 36 12 37 12 38 13 39 13 40 13 41 14 42 14 43 14 44 15 45 15 46 15 47 16 48 16 49 16 50 17 51 17 52 17 53 18 54 18...
output:
Different tree
result:
wrong answer Wrong Answer