QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710886#4549. Alice和Bob又在玩游戏D060 90ms33052kbC++142.2kb2024-11-04 22:49:102024-11-04 22:49:12

Judging History

你现在查看的是最新测评结果

  • [2024-11-04 22:49:12]
  • 评测
  • 测评结果:0
  • 用时:90ms
  • 内存:33052kb
  • [2024-11-04 22:49:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
vector<int>a[100005];
bool v[100005];
int tot,t[100000*18+5][2],s[100000*18+5],bj[100000*18+5];
int sg[100005];
void pushdown(int p,int k)
{
	if((bj[p]>>k)&1)
	{
		swap(t[t[p][0]][0],t[t[p][0]][1]);
		swap(t[t[p][1]][0],t[t[p][1]][1]);
	}
	bj[t[p][0]]^=bj[p];
	bj[t[p][1]]^=bj[p];
	bj[p]=0;
}
int merge(int p,int q,int x,int k)
{
	if(k==-2)
	{
		return 0;
	}
	if(!p&&!q)
	{
		return 0;
	}
	if(!p)
	{
		if((x>>k)&1)
		{
			swap(t[q][0],t[q][1]);
		}
		bj[q]^=x;
		return q;
	}
	if(!q)
	{
		if((x>>k)&1)
		{
			swap(t[p][0],t[p][1]); 
		}
		bj[p]^=x;
		return p;
	}
	if(k>=1)
	{
		pushdown(p,k-1);
		pushdown(q,k-1);
	}
	t[p][0]=merge(t[p][0],t[q][(x>>k)&1],x,k-1);
	t[p][1]=merge(t[p][1],t[q][((x>>k)&1)^1],x,k-1);
	s[p]=s[t[p][0]]+s[t[p][1]]+(k==-1);
	return p;
}
int ask(int p,int k)
{
	if(k==-1)
	{
		return 0;
	}
	if(s[t[p][0]]==(1<<k))
	{
		return (1<<k)+ask(t[p][1],k-1);
	}
	else
	{
		return ask(t[p][0],k-1);
	}
}
void insert(int p,int x,int k)
{
	if(k==-1)
	{
		s[p]=1;
		return;
	}
	if(!t[p][(x>>k)&1])
	{
		t[p][(x>>k)&1]=++tot;
		t[tot][0]=t[tot][1]=s[tot]=bj[tot]=0;
	}
	insert(t[p][(x>>k)&1],x,k-1);
	s[p]=s[t[p][0]]+s[t[p][1]];
}
void dfs(int n1,int fa)
{
	v[n1]=true;
	int sum=0;
	for(int i=0;i<a[n1].size();i++)
	{
		if(a[n1][i]!=fa)
		{
			dfs(a[n1][i],n1);
			sum=sum^sg[a[n1][i]];
		}
	}
	for(int i=0;i<a[n1].size();i++)
	{
		if(a[n1][i]!=fa)
		{
			sum=sum^sg[a[n1][i]];
			merge(n1,a[n1][i],sum,16);
			sum=sum^sg[a[n1][i]];
		}
	}
	insert(n1,sum,16);
	sg[n1]=ask(n1,16);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			v[i]=false;
			a[i].clear();
			t[i][0]=t[i][1]=s[i]=bj[i]=0;
			sg[i]=0;
		}
		for(int i=1;i<=m;i++)
		{
			int u,v;
			cin>>u>>v;
			a[u].push_back(v);
			a[v].push_back(u);
		}
		int ans=0;
		tot=n;
		for(int i=1;i<=n;i++)
		{
			if(!v[i])
			{
				dfs(i,0);
				ans=ans^sg[i];
			}
		}
		cout<<ans<<"\n";
		if(ans==0)
		{
			cout<<"Bob\n";
		}
		else
		{
			cout<<"Alice\n";
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 10840kb

input:

6
3 0
5 0
7 0
4 0
6 0
8 0

output:

1
Alice
1
Alice
1
Alice
0
Bob
0
Bob
0
Bob

result:

wrong answer 1st lines differ - expected: 'Alice', found: '1'

Test #2:

score: 0
Wrong Answer
time: 2ms
memory: 12044kb

input:

6
13 0
15 0
7 0
14 0
16 0
18 0

output:

1
Alice
1
Alice
1
Alice
0
Bob
0
Bob
0
Bob

result:

wrong answer 1st lines differ - expected: 'Alice', found: '1'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 11568kb

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:

13
Alice
2
Alice
12
Alice
18
Alice
5
Alice
10
Alice
14
Alice
0
Bob
14
Alice
2
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '13'

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 11388kb

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:

0
Bob
0
Bob
9
Alice
13
Alice
2
Alice
0
Bob
9
Alice
9
Alice
14
Alice
13
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '0'

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 10324kb

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:

0
Bob
34
Alice
37
Alice
16
Alice
5
Alice
0
Bob
22
Alice
36
Alice
15
Alice
35
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '0'

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 11412kb

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:

5
Alice
34
Alice
25
Alice
42
Alice
48
Alice
14
Alice
1
Alice
54
Alice
17
Alice
39
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '5'

Test #7:

score: 0
Wrong Answer
time: 2ms
memory: 12128kb

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:

13
Alice
16
Alice
25
Alice
24
Alice
32
Alice
1
Alice
28
Alice
20
Alice
9
Alice
36
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '13'

Test #8:

score: 0
Wrong Answer
time: 2ms
memory: 10632kb

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:

3
Alice
10
Alice
19
Alice
6
Alice
50
Alice
6
Alice
15
Alice
45
Alice
2
Alice
38
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '3'

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 10596kb

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:

2
Alice
209
Alice
240
Alice
234
Alice
20
Alice
1
Alice
185
Alice
178
Alice
214
Alice
139
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '2'

Test #10:

score: 0
Wrong Answer
time: 4ms
memory: 10332kb

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:

11
Alice
14
Alice
214
Alice
38
Alice
263
Alice
14
Alice
6
Alice
248
Alice
148
Alice
50
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '11'

Test #11:

score: 0
Wrong Answer
time: 4ms
memory: 10488kb

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:

1
Alice
259
Alice
171
Alice
3
Alice
262
Alice
6
Alice
221
Alice
263
Alice
4
Alice
159
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '1'

Test #12:

score: 0
Wrong Answer
time: 4ms
memory: 10484kb

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:

14
Alice
168
Alice
311
Alice
0
Bob
166
Alice
205
Alice
64
Alice
64
Alice
0
Bob
305
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '14'

Test #13:

score: 0
Wrong Answer
time: 88ms
memory: 32956kb

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:

124
Alice
6853
Alice
22
Alice
928
Alice
768
Alice
38
Alice
516
Alice
549
Alice
30
Alice
581
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '124'

Test #14:

score: 0
Wrong Answer
time: 90ms
memory: 28752kb

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:

114
Alice
6625
Alice
546
Alice
523
Alice
655
Alice
78
Alice
106
Alice
641
Alice
512
Alice
299
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '114'

Test #15:

score: 0
Wrong Answer
time: 89ms
memory: 31048kb

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:

6855
Alice
56
Alice
61
Alice
34
Alice
768
Alice
29
Alice
83
Alice
43
Alice
29
Alice
896
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '6855'

Test #16:

score: 0
Wrong Answer
time: 89ms
memory: 28796kb

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:

120
Alice
6784
Alice
29
Alice
779
Alice
512
Alice
647
Alice
52
Alice
29
Alice
0
Bob
797
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '120'

Test #17:

score: 0
Wrong Answer
time: 77ms
memory: 33052kb

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:

5378
Alice
98
Alice
8
Alice
832
Alice
3
Alice
23
Alice
0
Bob
647
Alice
55
Alice
37
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '5378'

Test #18:

score: 0
Wrong Answer
time: 77ms
memory: 30660kb

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:

103
Alice
5961
Alice
1089
Alice
165
Alice
21
Alice
744
Alice
576
Alice
898
Alice
60
Alice
552
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '103'

Test #19:

score: 0
Wrong Answer
time: 82ms
memory: 30912kb

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:

3582
Alice
53
Alice
796
Alice
3
Alice
93
Alice
18
Alice
47
Alice
540
Alice
669
Alice
703
Alice

result:

wrong answer 1st lines differ - expected: 'Alice', found: '3582'

Test #20:

score: 0
Wrong Answer
time: 88ms
memory: 30860kb

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:

62
Alice
802
Alice
62
Alice
42
Alice
841
Alice
454
Alice
798
Alice
113
Alice
57
Alice
60
Alice

result:

wrong answer 1st lines differ - expected: 'Bob', found: '62'