QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#55556 | #4549. Alice和Bob又在玩游戏 | The_Nobody | 100 ✓ | 109ms | 41492kb | C++ | 2.5kb | 2022-10-14 15:31:58 | 2022-10-14 15:32:01 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define Il inline
#define mem(u,v) memset(u,v,sizeof(u))
#define rep(i,a,b) for(ll i=(a),KKK##i=(b);i<=KKK##i;i++)
#define drep(i,a,b) for(ll i=(a),KKK##i=(b);i>=KKK##i;i--)
#define go(u) for(ll i=head[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define writesp(x) write(x),putchar(' ')
#define writeln(x) write(x),puts("")
using namespace std;
Il ll read(){ll sum=0,f=0;char ch=getchar();for(;!isdigit(ch);ch=getchar())f|=(ch=='-');for(;isdigit(ch);ch=getchar())sum=((sum<<1)+(sum<<3)+(ch^48));return f?-sum:sum;}
void write(const ll x){if(x<0){putchar('-');write(-x);return;}if(x>9)write(x/10);putchar(x%10+'0');}
char getc(){char c=getchar();while(!isalpha(c))c=getchar();return c;}
#define N 1100000
ll n,m,x,y,tot,head[N],ans[N],S[N],RT[N];bool vis[N];
struct node{ll to,nxt;}e[N*2];
void add(ll f,ll to){e[++tot].to=to;e[tot].nxt=head[f];head[f]=tot;}
#define LC ch[rt][0]
#define RC ch[rt][1]
ll sum[N<<5],lz[N<<5],ch[N][2],cnt;
void pushup(ll rt){sum[rt]=sum[LC]+sum[RC];}
void pushdown(ll rt,ll dep){
if(!lz[rt])return;
if((lz[rt]>>(dep-1))&1)swap(ch[rt][0],ch[rt][1]);
lz[LC]^=lz[rt];lz[RC]^=lz[rt];
lz[rt]=0;
}
void updata(ll&rt,ll dep,ll k){
if(!rt)rt=++cnt;
// cout<<"JA"<<rt<<' '<<dep<<' '<<k<<endl;
if(!dep)return sum[rt]=1,void();pushdown(rt,dep);
ll tmp=(k>>(dep-1))&1;
// cout<<tmp<<endl;
updata(ch[rt][tmp],dep-1,k);
pushup(rt);
}
ll merge(ll rt,ll _rt,ll dep){
if(!rt||!_rt)return rt|_rt;
if(!dep){
sum[rt]|=sum[_rt];
return rt;
}pushdown(rt,dep);pushdown(_rt,dep);
sum[rt]+=sum[_rt];
LC=merge(LC,ch[_rt][0],dep-1);
RC=merge(RC,ch[_rt][1],dep-1);
pushup(rt);return rt;
}
ll query(ll rt,ll dep,ll S){
// cout<<"D"<<rt<<' '<<dep<<" "<<S<<' '<<sum[rt]<<' '<<sum[ch[rt][0]]<<' '<<sum[ch[rt][1]]<<endl;
if(!dep)return S;pushdown(rt,dep);
if(sum[ch[rt][0]]==(1ll<<(dep-1)))return query(RC,dep-1,S*2+1);
// puts("LEFT");
return query(LC,dep-1,S*2);
}
void tag(ll rt,ll k){
lz[rt]^=k;
}
void dfs(ll u,ll fa){
vis[u]=1;
go(u)if(v!=fa)dfs(v,u),S[u]^=ans[v];
go(u)if(v!=fa)tag(RT[v],S[u]^ans[v]),RT[u]=merge(RT[u],RT[v],20);
// cout<<query(RT[u],20,0)<<endl;
updata(RT[u],20,S[u]);
ans[u]=query(RT[u],20,0);
// cout<<"DE"<<u<<" "<<S[u]<<" "<<ans[u]<<endl;
}
int main(){
drep(__,read(),1){
n=read();m=read();ll HA=0;
rep(i,1,m)x=read(),y=read(),add(x,y),add(y,x);
rep(i,1,n)if(!vis[i])dfs(i,0),HA^=ans[i];
puts(HA==0?"Bob":"Alice");
rep(i,1,n)vis[i]=0,head[i]=0,RT[i]=0,S[i]=0,ans[i]=0;tot=0;
rep(i,1,cnt)ch[i][0]=ch[i][1]=0;cnt=0;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 3720kb
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: 2ms
memory: 3544kb
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: 2ms
memory: 3532kb
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: 3500kb
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: 2ms
memory: 3776kb
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: 2ms
memory: 3604kb
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: 2ms
memory: 3544kb
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: 0ms
memory: 3600kb
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: 1ms
memory: 4288kb
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: 5ms
memory: 4208kb
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: 4236kb
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: 2ms
memory: 4144kb
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: 95ms
memory: 40884kb
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: 97ms
memory: 41220kb
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: 109ms
memory: 41352kb
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: 97ms
memory: 41256kb
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: 98ms
memory: 41444kb
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: 97ms
memory: 39932kb
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: 108ms
memory: 41356kb
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: 105ms
memory: 41492kb
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