QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#345672 | #4549. Alice和Bob又在玩游戏 | monster_hunter | 100 ✓ | 134ms | 29316kb | C++14 | 2.9kb | 2024-03-07 11:42:07 | 2024-03-07 11:42:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define LL long long
struct edge{
LL to,nt;
}a[400005];
LL son[8000005][2];
LL nxt[400005],root[400005],val[400005];
LL sum[8000005];
LL tmp[400005];
LL sg[400005];
queue<LL> q;
bool vis[400005];
LL n,i,j,k,m,cnt=0,x,y,ans,t;
void add(LL x,LL y){
a[++cnt].to=y;a[cnt].nt=nxt[x];nxt[x]=cnt;
}
void insert(LL x,LL num,LL step){
if(step==-1){
sum[x]=1;
return ;
}
LL tmp=(num>>(step))&1;
if(son[x][tmp]==0){
if(!q.empty()){
son[x][tmp]=q.front();
son[q.front()][0]=son[q.front()][1]=0;
q.pop();
}
else son[x][tmp]=++cnt;
}
//printf("%lld %lld %lld\n",x,son[x][0],son[x][1]);
insert(son[x][tmp],num,step-1);
sum[x]=sum[son[x][0]]+sum[son[x][1]];
//printf("%lld %lld %lld\n",x,sum[x],step);
}
LL getnum(LL x,LL num,LL step){
if(step==-1) return 0;
if(x==0) return 0;
LL tmp=(num>>(step))&1;
//printf("%lld %lld %lld\n",x,step,num);
if(sum[son[x][tmp]]!=(1<<(step))) return getnum(son[x][tmp],num,step-1);
else return getnum(son[x][tmp^1],num,step-1)+(1<<(step));
}
void merge(LL x,LL y,LL num,LL step){
q.push(y);
if(step==-1){
insert(root[x],num^val[x],20);
return ;
}
LL num0=son[y][0],num1=son[y][1];
if(num0>0) merge(x,num0,num,step-1);
if(num1>0) merge(x,num1,num^(1<<step),step-1);
}
void dfs(LL father,LL x){
vis[x]=true;
LL now=0,sum1=0,num=0;
for(LL i=nxt[x];i;i=a[i].nt)
if(a[i].to!=father){
dfs(x,a[i].to);
sum1++;
num^=sg[a[i].to];
}
if(sum1==0){
sg[x]=1;
root[x]=++cnt;
val[x]=1;
tmp[x]=1;
insert(root[x],0,20);
insert(root[x],1,20);
return ;
}
for(LL i=nxt[x];i;i=a[i].nt)
if(a[i].to!=father){
if(now==0){
now=a[i].to;
}
else{
//printf("%lld %lld %lld %lld\n",x,a[i].to,tmp[x],tmp[a[i].to]);
if(tmp[x]<tmp[a[i].to]){
merge(a[i].to,root[now],val[now],20);
now=a[i].to;
}
else merge(now,root[a[i].to],val[a[i].to],20);
}
tmp[x]+=tmp[a[i].to];
}
tmp[x]++;
//printf("%lld %lld\n",x,now);
root[x]=root[now];
val[x]=val[now];
val[x]^=num;
sg[x]=getnum(root[x],val[x],20);
insert(root[x],val[x]^sg[x],20);
//printf("%lld %lld\n",x,num);
val[x]^=sg[x];
}
int main(){
scanf("%lld",&t);
while(t--){
scanf("%lld%lld",&n,&m);
for(i=1;i<=n;i++)
vis[i]=false,nxt[i]=0,root[i]=0,val[i]=0,sg[i]=0;
while(!q.empty()) q.pop();
for(i=1;i<=cnt;i++)
sum[i]=son[i][0]=son[i][1]=0;
cnt=0;
for(i=1;i<=m;i++){
scanf("%lld%lld",&x,&y);
add(x,y);add(y,x);
}
cnt=0;
ans=0;
for(i=1;i<=n;i++)
if(vis[i]==false){
dfs(0,i);
ans^=sg[i];
//printf("%lld ",sg[i]);
}
/*for(i=1;i<=n;i++)
printf("%lld ",sg[i]);
printf("\n");
for(i=1;i<=n;i++)
printf("%lld ",sum[i]);
printf("\n");*/
if(ans>0) printf("Alice\n");
else printf("Bob\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 1ms
memory: 3824kb
input:
6 3 0 5 0 7 0 4 0 6 0 8 0
output:
Alice Alice Alice Bob Bob Bob
result:
ok 6 lines
Test #2:
score: 5
Accepted
time: 0ms
memory: 3852kb
input:
6 13 0 15 0 7 0 14 0 16 0 18 0
output:
Alice Alice Alice Bob Bob Bob
result:
ok 6 lines
Test #3:
score: 5
Accepted
time: 0ms
memory: 3716kb
input:
10 20 15 6 11 1 12 12 6 2 12 18 7 3 16 10 9 10 12 19 17 10 15 19 7 14 15 7 20 18 10 3 12 20 17 3 7 1 12 8 16 20 2 16 15 18 11 1 16 19 6 13 14 19 9 1 5 18 4 14 20 9 16 17 19 7 16 20 10 20 18 1 7 4 19 14 6 14 1 11 17 3 19 9 18 20 2 12 1 8 1 17 15 16 13 13 5 10 1 20 9 17 13 5 3 8 18 20 19 15 10 2 6 1 4...
output:
Alice Bob Bob Alice Bob Alice Bob Bob Alice Bob
result:
ok 10 lines
Test #4:
score: 5
Accepted
time: 1ms
memory: 3768kb
input:
10 20 17 11 7 8 2 13 6 1 8 10 8 11 4 19 12 18 16 15 14 20 17 13 9 12 9 15 10 12 2 9 16 3 16 7 15 20 17 20 12 7 1 7 3 12 13 1 5 9 18 18 5 17 5 16 11 12 11 10 5 8 2 4 12 14 12 6 11 11 1 15 5 20 18 12 15 13 19 8 9 7 12 8 1 5 8 19 6 16 12 12 18 8 3 5 19 17 9 7 3 13 20 15 10 2 11 4 13 2 15 20 19 3 4 12 5...
output:
Bob Bob Alice Alice Alice Bob Bob Alice Alice Alice
result:
ok 10 lines
Test #5:
score: 5
Accepted
time: 1ms
memory: 3804kb
input:
10 100 23 40 24 46 52 47 49 30 16 94 1 91 81 99 49 32 98 97 40 6 100 32 76 21 41 35 68 3 100 17 8 13 76 36 25 13 97 1 74 82 6 2 48 7 73 15 63 100 98 36 27 8 70 71 65 83 71 82 97 32 48 4 38 1 79 4 60 12 20 95 78 83 7 99 5 67 32 86 11 1 65 59 5 29 57 85 1 34 4 54 71 83 29 52 85 51 22 95 65 5 18 3 91 5...
output:
Bob Bob Alice Alice Bob Bob Bob Alice Alice Bob
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 0ms
memory: 4088kb
input:
10 100 41 86 2 69 67 60 51 75 97 87 95 82 81 86 14 52 65 51 42 40 10 55 11 51 85 14 61 23 90 44 53 78 40 76 96 12 31 49 80 53 41 72 88 97 30 15 32 47 20 41 79 29 72 59 100 22 95 65 30 3 21 43 88 75 57 69 37 38 64 80 5 42 53 58 46 73 24 34 68 88 48 81 33 100 78 22 4 15 4 78 100 58 24 81 9 7 43 22 61 ...
output:
Alice Bob Bob Alice Alice Alice Bob Bob Alice Alice
result:
ok 10 lines
Test #7:
score: 5
Accepted
time: 1ms
memory: 4048kb
input:
10 100 31 17 7 24 21 43 21 34 20 100 59 83 47 3 76 3 39 9 29 81 3 49 80 46 34 74 100 8 46 8 70 69 7 45 1 79 31 60 46 26 72 33 30 97 65 100 52 4 27 57 64 45 8 66 51 29 51 1 48 11 21 4 35 100 67 96 16 78 11 74 57 81 70 90 32 87 5 73 75 13 100 88 84 49 62 85 9 61 7 73 7 92 37 59 88 28 26 4 7 10 84 33 6...
output:
Alice Alice Bob Bob Alice Alice Alice Bob Bob Alice
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 1ms
memory: 3804kb
input:
10 100 43 96 2 10 70 34 6 82 98 27 66 96 40 60 36 82 10 74 75 68 100 12 55 25 14 83 29 38 10 73 59 77 20 67 54 20 52 26 83 76 92 21 45 82 43 29 15 2 99 64 43 90 27 7 19 99 18 28 88 85 34 81 46 30 62 51 13 55 61 71 68 31 1 56 4 37 89 92 49 87 18 23 5 74 34 83 31 100 42 33 62 32 72 82 79 34 9 15 24 71...
output:
Bob Alice Alice Bob Alice Bob Alice Alice Bob Alice
result:
ok 10 lines
Test #9:
score: 5
Accepted
time: 4ms
memory: 4420kb
input:
10 1000 43 772 422 642 2 299 28 330 35 12 520 59 471 298 696 526 289 692 263 518 5 786 236 261 324 676 859 644 140 891 162 903 718 870 597 47 695 135 212 438 567 972 408 238 405 62 913 939 696 717 602 612 991 642 99 878 347 755 679 281 216 506 180 633 712 455 621 878 791 354 515 196 712 449 48 76 10...
output:
Alice Alice Bob Bob Alice Alice Alice Bob Bob Alice
result:
ok 10 lines
Test #10:
score: 5
Accepted
time: 4ms
memory: 4496kb
input:
10 1000 553 733 308 955 950 122 694 335 139 579 404 360 386 761 48 713 69 885 900 572 425 407 375 660 441 712 175 581 570 552 42 30 550 905 619 406 361 641 83 372 903 116 126 622 940 633 378 171 954 672 571 985 991 426 818 512 276 801 969 604 567 51 104 239 826 603 404 84 401 152 219 790 216 773 457...
output:
Bob Bob Alice Bob Alice Bob Bob Alice Bob Alice
result:
ok 10 lines
Test #11:
score: 5
Accepted
time: 2ms
memory: 4396kb
input:
10 1000 123 514 970 370 473 77 91 436 836 896 508 624 417 472 282 332 981 478 210 261 983 111 853 977 115 604 43 315 322 459 748 34 696 156 976 458 677 444 481 185 717 478 284 411 104 452 780 551 298 610 543 184 700 652 111 390 537 836 377 418 218 69 353 509 371 154 733 561 307 592 734 566 784 183 7...
output:
Alice Alice Bob Bob Bob Alice Alice Bob Bob Bob
result:
ok 10 lines
Test #12:
score: 5
Accepted
time: 4ms
memory: 4328kb
input:
10 1000 754 37 554 412 364 267 659 867 456 45 647 232 357 238 962 481 983 282 762 899 857 959 444 767 165 510 37 311 407 638 201 670 539 338 911 509 906 390 10 455 106 989 874 806 355 262 169 635 666 2 727 522 9 696 951 35 637 650 887 651 79 629 572 721 60 221 307 337 485 174 617 644 696 252 133 854...
output:
Bob Alice Bob Bob Alice Bob Alice Bob Bob Alice
result:
ok 10 lines
Test #13:
score: 5
Accepted
time: 124ms
memory: 28536kb
input:
10 84430 84368 1 4154 4154 25649 3265 25649 3265 29300 29300 21812 3168 21812 19245 3168 19245 38447 8585 38447 8585 20837 24822 20837 11564 24822 11564 22829 31085 22829 16 31085 8178 16 8178 1261 1261 34782 34782 5026 31221 5026 17991 31221 17991 3048 34807 3048 34807 25533 25533 27170 27170 5175 ...
output:
Bob Alice Bob Alice Alice Bob Alice Alice Bob Alice
result:
ok 10 lines
Test #14:
score: 5
Accepted
time: 134ms
memory: 28400kb
input:
10 84806 84743 28461 1 28461 9961 9961 35696 35696 5273 5273 29126 29126 38289 38289 23507 23507 9 10 9 10 9186 9186 33743 5756 33743 5756 21120 15 21120 15 7483 7276 7483 7276 2978 2978 9436 9436 30448 30448 29729 29729 35238 35791 35238 19782 35791 25 19782 25 2780 15719 2780 397 15719 397 3758 37...
output:
Bob Alice Alice Alice Alice Bob Bob Alice Alice Alice
result:
ok 10 lines
Test #15:
score: 5
Accepted
time: 122ms
memory: 28776kb
input:
10 82084 82065 37775 32530 40546 29469 23566 28044 35617 31751 31166 43373 28423 2499 11536 19058 23290 31161 26226 24568 18877 6176 9262 43955 18274 17232 32859 41405 20598 36180 21792 578 29778 31253 27189 4111 42776 34788 873 11571 15705 10303 8278 13795 5914 28364 32028 26693 36908 42138 11907 2...
output:
Alice Bob Bob Bob Alice Bob Bob Bob Bob Alice
result:
ok 10 lines
Test #16:
score: 5
Accepted
time: 127ms
memory: 28908kb
input:
10 85000 84953 24621 1 24621 36903 36903 4 33359 4 33359 6 6 29846 29846 39656 39656 9 9 38842 10565 38842 10565 19413 19413 37160 37160 23025 23025 25488 25488 16 16 28458 28458 3388 22598 3388 20 22598 23875 20 37611 23875 16745 37611 16745 25981 16207 25981 16207 11402 18861 11402 18861 2058 2757...
output:
Bob Alice Bob Alice Alice Alice Bob Bob Bob Alice
result:
ok 10 lines
Test #17:
score: 5
Accepted
time: 120ms
memory: 28836kb
input:
10 83316 83299 10033 32368 47502 24728 31682 30118 43973 15341 5822 34318 29780 19772 45970 34626 28002 797 9591 26973 35005 44537 33032 26612 30988 48652 33749 5045 5955 32860 44207 15678 28034 24354 29690 2207 17753 29140 9885 14486 28101 29900 20137 36123 13949 20079 21555 8761 16072 10804 42675 ...
output:
Alice Bob Bob Alice Bob Bob Bob Alice Bob Bob
result:
ok 10 lines
Test #18:
score: 5
Accepted
time: 126ms
memory: 27608kb
input:
10 82231 82168 1 1849 30163 1849 30163 4532 4532 17392 11875 17392 11875 11168 11168 37043 37043 18205 18205 34868 34868 16425 11835 16425 21736 11835 21736 14 4486 14 2419 4486 2419 30930 501 30930 501 10928 10928 299 14095 299 4469 14095 3550 4469 3550 31592 11679 31592 11679 26 26 31897 31897 324...
output:
Bob Alice Alice Alice Bob Alice Alice Alice Bob Alice
result:
ok 10 lines
Test #19:
score: 5
Accepted
time: 117ms
memory: 28708kb
input:
10 79873 79846 45043 31880 4441 30102 36418 17276 10371 28976 35848 28078 18719 6580 31379 47630 7873 25955 32444 31752 24751 26584 3314 3592 24794 29329 36094 45059 40891 8323 47741 45072 30083 33370 40224 35035 32323 38086 43309 12826 5965 47743 23015 25030 24013 37134 39574 22806 46940 40786 8273...
output:
Alice Bob Alice Bob Bob Bob Bob Alice Alice Alice
result:
ok 10 lines
Test #20:
score: 5
Accepted
time: 131ms
memory: 29316kb
input:
10 85000 84974 35180 1 34572 35180 34572 5302 2266 5302 2266 6 12139 6 12139 8 8 20653 10 20653 8479 10 20975 8479 20975 2030 14373 2030 12416 14373 9969 12416 9969 34877 34877 15729 15729 36050 21424 36050 33717 21424 33717 27572 27572 20518 20518 3624 38796 3624 38796 8762 27 8762 27 34615 34615 3...
output:
Bob Alice Bob Bob Alice Alice Alice Alice Bob Bob
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed