QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#558600 | #8220. 众生之门 | piggy123 | 27 | 175ms | 11260kb | C++20 | 4.7kb | 2024-09-11 17:02:43 | 2024-09-11 17:02:43 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> vct[50005];
ll son[50005],top[50005],f[50005],sz[50005],dep[50005],vis[50005],p[50005];
ll nwans[50005],mi,nw,n,s,t;
void dfs(ll root,ll fa) {
f[root]=fa;
dep[root]=dep[fa]+1;
sz[root]=1;son[root]=0;
for (ll i:vct[root]) {
if (i!=fa) {
dfs(i,root);
sz[root]+=sz[i];
if (sz[i]>sz[son[root]])son[root]=i;
}
}
}
void dfs2(ll root,ll fa,ll tp){
top[root]=tp;
if (son[root])dfs2(son[root],root,tp);
for (ll i:vct[root]){
if (i!=fa&&i!=son[root]){
dfs2(i,root,i);
}
}
}
inline ll lca(ll u,ll v) {
while (top[u]!=top[v]){
if (dep[top[u]]<dep[top[v]])swap(u,v);
u=f[top[u]];
}
return (dep[u]<dep[v]?u:v);
}
inline ll getdis(ll u,ll v) {
if (u<1||u>n||v<1||v>n)return 0;
return dep[u]+dep[v]-2*dep[lca(u,v)];
}
int main() {
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
ll T;
cin >> T;
while (T--) {
cin>>n>> s >> t;
for (ll i=1; i<=n; i++)vct[i].clear(),vis[i]=0;
for (ll i=1; i<=n-1; i++) {
ll u,v;
cin >> u >> v;
vct[u].push_back(v);
vct[v].push_back(u);
}
dfs(1,0);
dfs2(1,0,1);
p[1]=s,p[n]=t;
vis[s]=vis[t]=1;
ll tot=1;
for (ll i=1;i<=n;i++)if (!vis[i])p[++tot]=i;
mi=n+1;
nw=0;
for (ll i=1; i<=n; i++)nwans[i]=p[i],nw^=(i==0?0:getdis(p[i],p[i-1]));
mi=nw;
if (n==2) {
for (ll i=1; i<=n; i++)cout<< nwans[i]<<" ";
cout<<"\n";
} else if (n==3) {
for (ll i=1; i<=n; i++)cout<< nwans[i]<<" ";
cout<<"\n";
} else {
mt19937 mt(time(0));
for (ll i=1; i<=10*n; i++) {
ll x=mt()%(n-2)+2,y=mt()%(n-2)+2;
while (x==y)x=mt()%(n-2)+2,y=mt()%(n-2)+2;
if (x>y)swap(x,y);
ll pnw=nw;
if (y-x==1) {
nw^=getdis(p[x-1],p[x]);
nw^=getdis(p[y],p[y+1]);
nw^=getdis(p[x-1],p[y]);
nw^=getdis(p[x],p[y+1]);
} else {
nw^=getdis(p[x-1],p[x]);
nw^=getdis(p[x+1],p[x]);
nw^=getdis(p[y],p[y+1]);
nw^=getdis(p[y],p[y-1]);
nw^=getdis(p[x-1],p[y]);
nw^=getdis(p[x+1],p[y]);
nw^=getdis(p[x],p[y-1]);
nw^=getdis(p[x],p[y+1]);
}
swap(p[x],p[y]);
if (nw<mi) {
mi=nw;
for (ll i=1; i<=n; i++)nwans[i]=p[i];
}
if (mi<2)break;
}
// cout<<"! "<<mi<< endl;
for (ll i=1; i<=n; i++)cout<< nwans[i]<<" ";
cout<<"\n";
}
}
return 0;
}
/*
■■■■■ ■■ ■■■ ■■■ ■ ■ ■ ■■■■ ■■■■
■ ■■ ■■ ■ ■■ ■ ■■ ■ ■ ■■ ■ ■■ ■■ ■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■■ ■■ ■■ ■ ■■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■ ■ ■■ ■■
■ ■ ■■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■■ ■ ■■■ ■ ■■■ ■■ ■■ ■■ ■■■
■■■■■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■ ■ ■■
■ ■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■ ■■
■ ■■ ■■■■ ■■■■ ■■ ■■ ■■■■■■ ■■■■
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5712kb
input:
114 6 5 6 2 6 1 6 4 5 3 1 6 4 6 3 6 2 4 4 1 6 4 1 5 5 3 6 6 1 5 2 1 2 4 6 2 4 3 2 6 6 1 3 6 5 3 1 6 4 2 2 5 6 3 1 5 3 2 4 1 5 4 3 6 3 4 3 4 2 3 1 4 4 3 6 3 1 2 3 6 3 4 3 1 6 5 1 5 3 2 1 2 4 2 2 3 5 2 6 1 4 2 1 5 2 4 1 6 2 3 6 6 5 1 4 2 6 5 1 3 2 6 3 2 4 4 1 2 4 3 4 1 4 6 2 5 3 5 4 6 1 4 6 2 5 4 6 1 ...
output:
5 1 2 3 4 6 3 1 2 4 5 6 6 2 3 4 5 1 6 4 5 3 2 1 3 2 4 5 6 1 3 1 2 4 3 6 4 5 2 1 3 1 4 5 2 1 2 3 5 6 4 5 2 3 4 6 1 4 2 3 1 2 1 3 4 6 5 1 5 4 2 6 3 3 6 4 2 5 1 2 5 1 3 6 4 3 1 2 5 6 4 5 6 2 4 1 3 1 3 2 4 5 4 1 3 2 3 1 2 5 4 1 3 2 4 3 4 1 2 5 1 3 4 2 5 3 4 2 1 5 6 2 4 1 3 4 5 2...
result:
wrong answer Your solution is worse than Jury's in test case 14. Yours:3 Jury's:1
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 17
Accepted
Test #11:
score: 17
Accepted
time: 111ms
memory: 5844kb
input:
14190 43 27 2 42 3 30 36 11 24 21 22 13 8 22 30 31 29 35 1 10 6 2 23 28 17 2 26 7 37 5 19 38 43 33 39 4 28 33 7 25 31 15 1 32 18 34 27 35 12 19 32 20 17 37 42 26 34 39 10 12 27 24 43 18 6 16 9 38 9 14 15 14 41 25 3 40 13 16 8 36 41 20 5 21 40 11 29 41 24 38 21 6 20 14 26 1 6 7 17 16 39 36 8 18 36 11...
output:
27 29 26 4 24 6 23 36 39 35 5 38 13 37 43 16 21 18 10 20 8 12 7 30 42 32 9 14 34 33 28 22 11 3 25 1 17 31 19 41 15 40 2 24 9 40 35 1 6 34 7 8 20 23 11 19 18 14 15 26 17 13 12 28 4 22 10 25 16 27 3 29 32 31 30 33 5 21 41 37 2 36 39 38 5 1 2 3 4 6 7 8 9 10 11 12 13 14 26 16 17 15 19 20 23 21 24 25 1...
result:
ok Answer correct!
Test #12:
score: 17
Accepted
time: 95ms
memory: 3676kb
input:
9236 52 51 21 5 3 51 16 20 49 5 34 46 33 28 34 10 23 14 45 51 9 44 11 52 6 15 37 44 14 24 35 50 2 41 27 21 47 17 4 12 43 22 26 41 39 18 45 40 50 33 1 29 21 19 35 19 49 22 43 36 16 39 11 17 42 30 25 27 30 37 46 47 38 23 48 7 12 9 13 10 26 28 25 8 52 32 29 6 13 36 32 2 31 15 18 8 1 4 38 48 24 42 40 7 ...
output:
51 1 2 3 4 5 6 7 8 9 10 11 12 13 50 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 14 52 21 49 36 11 2 43 7 4 24 13 18 44 28 33 50 46 9 40 30 35 42 45 25 5 38 6 48 29 27 31 51 22 1 3 12 26 34 21 19 39 20 37 15 14 8 17 41 10 16 47 23 32 30 39 2...
result:
ok Answer correct!
Test #13:
score: 17
Accepted
time: 80ms
memory: 5748kb
input:
7430 56 55 12 1 32 29 36 45 8 33 47 29 56 36 13 3 24 5 11 55 39 4 34 46 34 37 23 35 53 56 54 7 44 1 27 12 20 28 54 25 19 51 6 42 38 15 30 37 25 38 3 16 39 12 52 41 9 50 53 22 26 11 13 18 55 33 15 27 6 47 28 43 14 23 22 21 9 48 49 4 2 14 31 10 52 5 18 20 40 2 42 17 31 51 49 48 21 16 43 41 44 50 46 40...
output:
55 36 2 52 47 27 6 38 8 9 32 5 13 14 15 16 29 18 19 20 21 11 23 24 25 26 30 28 17 51 31 46 33 34 35 1 37 48 39 40 7 42 43 44 45 10 4 41 49 50 22 3 53 54 56 12 24 39 31 48 8 57 23 20 9 30 18 27 7 37 15 45 44 46 22 50 26 28 14 56 54 51 40 47 36 19 11 33 52 29 42 5 41 6 4 25 3 43 16 2 53 12 34 35 32 2...
result:
ok Answer correct!
Test #14:
score: 17
Accepted
time: 101ms
memory: 5732kb
input:
9765 42 15 16 22 4 6 9 42 6 25 20 22 24 9 39 2 13 36 11 5 21 11 18 7 34 4 35 42 10 16 10 29 30 29 8 17 30 12 40 34 39 27 15 27 3 17 31 2 19 12 14 41 23 15 16 36 1 28 38 13 40 38 33 41 24 8 37 37 18 7 35 26 5 28 20 33 31 1 26 32 14 32 21 23 19 18 3 16 11 6 16 9 11 13 8 4 17 7 18 15 8 9 14 13 17 4 16 ...
output:
15 1 4 22 34 36 6 31 13 40 10 21 12 41 8 42 32 19 20 17 35 23 24 37 5 27 28 18 30 26 11 33 2 3 7 39 38 25 9 14 29 16 3 1 2 6 5 8 7 12 9 10 11 4 13 14 15 17 18 16 9 14 2 3 17 19 1 12 8 10 11 5 13 6 15 7 18 4 16 6 36 12 3 26 5 7 42 9 44 35 15 14 4 16 17 27 28 25 1 21 23 29 22 13 37 8 24 30 31 32 45...
result:
ok Answer correct!
Test #15:
score: 17
Accepted
time: 89ms
memory: 3816kb
input:
1969 144 119 17 109 11 66 80 131 133 76 89 128 137 80 77 141 114 98 94 55 68 115 41 31 78 104 123 106 138 18 37 72 100 38 14 15 86 87 136 41 99 26 56 130 84 67 1 28 96 92 88 12 137 11 102 13 42 48 93 79 43 51 98 100 130 131 59 38 52 24 117 7 19 93 135 135 29 35 101 46 62 47 39 99 85 122 87 123 70 11...
output:
119 31 2 5 4 41 126 19 8 127 10 11 24 13 14 15 16 12 7 71 21 22 26 97 67 98 1 28 59 30 27 51 38 132 35 36 89 33 134 112 57 42 105 44 45 46 47 48 49 29 32 52 53 102 128 143 54 9 117 129 20 25 18 120 114 66 73 137 131 91 56 72 3 94 75 76 103 78 79 80 81 82 83 84 85 23 104 121 37 135 70 92 93 74 95 96 ...
result:
ok Answer correct!
Test #16:
score: 17
Accepted
time: 95ms
memory: 6100kb
input:
500 844 123 801 629 492 828 294 203 630 621 178 604 159 4 26 750 486 123 709 100 83 66 161 682 411 547 837 812 104 8 394 402 547 312 607 396 823 320 564 251 504 640 315 295 301 703 706 789 222 64 672 272 19 78 38 754 555 543 498 74 466 236 472 155 125 491 700 794 192 62 169 637 407 540 385 122 106 4...
output:
123 689 447 337 4 778 6 359 122 14 10 321 462 833 197 627 16 17 185 19 673 212 182 812 24 64 459 59 672 597 721 80 368 206 134 711 766 730 781 39 40 642 73 533 190 581 396 328 562 49 50 285 455 450 568 101 432 350 103 702 327 558 444 189 815 65 120 67 443 263 466 336 174 560 74 662 418 338 484 640 3...
result:
ok Answer correct!
Test #17:
score: 17
Accepted
time: 175ms
memory: 11260kb
input:
34 33100 10117 18164 18635 32475 7408 21287 9517 5145 22923 26110 26263 11123 14870 20414 5233 11462 22918 19251 12631 11482 24262 28772 16262 4688 22280 31365 10129 23488 17195 15430 4602 1331 20453 6886 13707 24978 15951 7988 4834 23333 22314 7430 4956 2681 6703 9446 9417 33087 5722 1217 18525 174...
output:
10117 10455 8758 31748 24210 22899 25701 14081 22824 15524 30124 10328 14467 11135 25920 14727 6678 10661 14260 25435 32939 134 27751 29088 28182 7390 28816 23917 13816 8959 27185 26714 12193 4915 9692 25569 19666 2588 11140 4706 11294 16917 19209 1568 5927 27429 9180 9632 27645 1755 28733 22966 111...
result:
ok Answer correct!
Subtask #4:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 138ms
memory: 3672kb
input:
32752 15 3 4 14 12 4 12 1 10 9 13 7 6 12 5 1 12 9 15 7 9 8 12 2 6 11 6 9 3 6 10 13 12 2 10 11 10 5 1 4 12 11 4 6 2 13 6 5 9 6 8 13 6 3 4 8 13 7 15 3 6 15 10 4 2 8 5 10 3 1 3 15 2 8 4 12 9 7 8 11 8 6 13 8 12 14 8 6 12 15 5 7 8 14 10 13 11 13 13 5 2 14 15 8 15 1 6 2 7 15 9 13 15 3 6 13 15 4 12 5 15 10...
output:
3 1 2 5 6 7 8 9 10 11 12 13 14 15 4 12 11 3 13 5 6 7 4 9 10 8 1 2 3 1 2 4 5 7 8 9 10 11 12 13 14 15 6 5 1 2 3 4 8 9 6 10 11 12 13 14 15 7 10 4 2 6 11 13 5 1 15 12 9 3 7 14 8 11 8 2 5 1 4 7 9 10 6 3 11 1 2 3 4 5 6 7 8 10 12 13 14 15 9 14 1 2 3 4 7 6 5 9 10 8 11 13 12 5 1 2 7 6 4 8 9 10 11 3 ...
result:
wrong answer Your solution is worse than Jury's in test case 21791. Yours:2 Jury's:0
Subtask #5:
score: 0
Wrong Answer
Test #25:
score: 0
Wrong Answer
time: 134ms
memory: 3816kb
input:
36059 13 9 4 5 9 10 3 3 1 13 5 12 5 7 4 2 8 8 10 4 9 11 7 6 11 1 4 13 12 6 4 12 13 9 11 2 6 12 9 12 8 5 7 6 5 3 3 7 10 8 1 5 2 10 13 10 8 3 1 5 9 4 8 6 11 7 13 13 5 1 10 12 13 9 4 11 9 2 11 8 10 12 1 4 9 2 2 12 3 2 12 11 8 2 7 4 5 1 4 1 11 7 10 9 6 9 13 10 12 7 5 11 9 12 10 9 8 3 10 8 5 4 13 13 7 6 ...
output:
9 12 2 13 7 6 5 3 10 8 11 1 4 12 11 2 13 4 5 7 3 9 10 8 1 6 10 4 1 11 6 2 13 3 9 7 12 5 8 1 3 8 6 2 9 5 12 10 11 7 4 10 8 2 13 6 5 4 3 11 9 7 1 12 6 12 2 1 4 5 7 3 10 11 9 13 8 1 2 3 4 5 6 7 9 10 11 12 13 8 7 1 2 4 6 5 8 9 10 3 11 12 3 13 7 6 5 4 9 8 10 2 1 4 1 2 3 5 7 8 9 10 11 12 13 6 6 ...
result:
wrong answer Your solution is worse than Jury's in test case 26912. Yours:3 Jury's:1
Subtask #6:
score: 10
Accepted
Test #34:
score: 10
Accepted
time: 3ms
memory: 3984kb
input:
10 1000 165 244 175 661 738 362 280 462 776 922 231 578 963 615 639 836 32 418 519 220 565 733 239 951 768 847 196 200 246 119 591 288 994 586 313 46 971 515 512 811 228 908 627 339 33 337 447 488 616 319 399 727 921 615 421 509 167 354 905 382 20 356 875 414 619 904 824 940 435 244 953 663 719 962 ...
output:
165 1 385 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 940 87 88 89 90 91 92 93 756 95 96 97 98 99 100 ...
result:
ok Answer correct!
Test #35:
score: 10
Accepted
time: 3ms
memory: 5968kb
input:
10 1000 382 266 590 318 797 98 35 830 950 354 905 784 998 709 853 583 165 498 288 727 822 759 576 543 193 715 883 839 847 872 255 61 995 187 125 742 575 697 621 939 711 248 445 683 848 907 171 215 511 807 196 453 166 930 231 716 327 96 866 680 909 549 188 554 33 273 486 74 32 577 37 573 376 148 709 ...
output:
382 1 385 3 127 832 6 7 8 9 10 11 88 13 14 15 16 17 18 19 20 21 22 23 24 25 986 27 28 29 30 31 32 33 34 35 36 37 722 39 40 41 42 43 44 141 46 47 48 49 50 401 410 662 54 55 56 717 913 59 60 256 62 63 797 814 66 67 68 69 70 71 72 145 74 433 76 430 965 79 305 81 901 83 84 85 802 219 12 89 971 160 92 93...
result:
ok Answer correct!
Test #36:
score: 10
Accepted
time: 3ms
memory: 5968kb
input:
10 1000 252 455 479 592 266 350 335 8 117 54 580 751 999 484 73 339 97 325 96 336 629 247 947 425 374 458 666 716 498 402 859 866 361 441 627 365 372 505 456 485 376 379 422 416 72 498 489 369 211 537 909 508 12 23 523 738 714 383 556 447 548 773 521 353 76 581 555 780 565 148 672 15 570 768 888 39 ...
output:
252 1 384 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 940 87 88 89 90 91 92 93 756 95 96 97 98 99 100 ...
result:
ok Answer correct!
Test #37:
score: 10
Accepted
time: 3ms
memory: 5836kb
input:
10 1000 304 234 651 949 290 646 953 375 867 994 71 810 114 466 924 223 583 869 947 766 627 169 100 616 847 801 20 138 886 364 320 941 866 188 408 606 762 366 842 325 934 184 122 918 736 773 348 289 876 770 913 227 274 176 727 87 18 280 305 595 774 884 441 582 328 711 829 836 891 503 45 971 804 500 6...
output:
304 1 385 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 814 66 67 68 69 70 71 72 73 74 75 76 77 965 79 80 81 82 83 84 85 940 87 88 89 90 160 92 93 756 95 96 97 98 99 1...
result:
ok Answer correct!
Test #38:
score: 10
Accepted
time: 3ms
memory: 3972kb
input:
10 1000 105 350 300 724 309 285 319 499 170 893 469 224 304 775 964 858 625 758 529 516 328 239 585 559 341 670 135 549 810 328 439 251 49 198 265 691 30 101 146 261 376 929 981 434 980 439 191 601 764 888 731 801 706 824 203 210 83 419 41 812 176 472 226 117 156 280 996 478 902 761 75 57 542 969 36...
output:
105 1 385 3 4 832 6 7 8 9 10 11 88 13 14 15 16 17 18 19 20 21 22 23 24 25 986 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 142 46 47 48 49 50 51 52 662 54 55 56 108 58 59 60 61 62 63 797 814 66 67 68 69 70 71 72 73 74 433 76 77 965 79 820 81 82 83 84 85 802 87 12 89 664 161 92 93 756 95 96 ...
result:
ok Answer correct!
Subtask #7:
score: 0
Skipped
Dependency #2:
0%