QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#951435#10179. 입자 가속기Matutino9 311ms9012kbC++171.2kb2025-03-26 11:16:392025-03-26 11:16:51

Judging History

This is the latest submission verdict.

  • [2025-03-26 11:16:51]
  • Judged
  • Verdict: 9
  • Time: 311ms
  • Memory: 9012kb
  • [2025-03-26 11:16:39]
  • Submitted

answer

#include<bits/stdc++.h>
#define reg register  
const int N=1e5+10;
int n,a[N],ans;
std::vector<int> G[N];
struct BIT{
	int c[N];
	inline void mdf(reg int x,reg int k){for (;x<=n;x+=x&-x) c[x]+=k;}
	inline int qry(reg int x){reg int res=0;for (;x;x-=x&-x) res+=c[x];return res;}
	inline void mdf(reg int l,reg int r,reg int k){mdf(l,k),mdf(r+1,-k);}
}T;
int dfn[N],dfc,sz[N],son[N],fa[N],dep[N],top[N];
void dfs1(reg int u,reg int fat=0){
	dep[u]=dep[fa[u]=fat]+(sz[u]=1);
	for (auto v:G[u]) if (v^fat) dfs1(v,u),sz[u]+=sz[v],sz[son[u]]<sz[v]?son[u]=v:0;
}
void dfs2(reg int u,reg int fst){
	top[u]=fst,dfn[u]=++dfc; if (!son[u]) return; dfs2(son[u],fst);
	for (auto v:G[u]) if (v!=fa[u]&&v!=son[u]) dfs2(v,v);
}
void initialize(int N, std::vector<int> A, std::vector<int> B){
	n=N; for (reg int i=1;i<=n;i++) a[i]=-1;
	for (reg int i=0;i<n-1;i++) A[i]++,B[i]++,G[A[i]].push_back(B[i]),G[B[i]].push_back(A[i]);
	dfs1(1),dfs2(1,1);
	return;
}
void dfs(reg int u){
	sz[u]=a[u]==1;
	for (auto v:G[u]) if (v^fa[u]) dfs(v),sz[u]+=sz[v];
	// std::cerr<<"<< "<<u<<" "<<sz[u]<<"\n";
	if (a[fa[u]]==0) ans+=sz[u]/2,sz[u]=0;
}
int generate(int v, bool result){
	v++,a[v]=result,ans=0;
	dfs(1);
	// std::cerr<<"--------\n";
	return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 9
Accepted

Test #1:

score: 9
Accepted
time: 0ms
memory: 7172kb

input:

2 2
0 1
0 1
1 1

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1

result:

ok 3 lines

Test #2:

score: 9
Accepted
time: 1ms
memory: 8152kb

input:

6 5
0 1
0 2
0 3
3 4
3 5
1 1
5 1
0 0
4 1
3 1

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
0
1
1

result:

ok 6 lines

Test #3:

score: 9
Accepted
time: 226ms
memory: 8516kb

input:

5000 5000
4000 193
193 3720
3720 2830
2830 1679
2830 3875
193 246
3720 2628
3720 2220
2220 749
2628 1622
1622 3105
4000 1742
193 1747
1622 1813
749 1537
3875 3418
1537 605
2220 3355
3418 2032
749 4629
4000 1787
4000 4981
1787 2204
246 938
2220 1576
4981 1872
938 3286
2032 4873
3875 2348
2204 654
193...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
26
27
27
28
28
29
29
29
30
30
31
31
32
32
32
33
33
34
34
35
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
43
44
44
...

result:

ok 5001 lines

Test #4:

score: 9
Accepted
time: 227ms
memory: 8396kb

input:

5000 5000
87 1282
87 1822
1822 3812
3812 182
3812 2019
87 833
1282 4672
182 3350
3350 992
2019 847
87 2786
1822 1640
847 4709
1640 4201
992 2589
1640 3262
833 4295
4295 1080
1080 639
3262 3818
847 1955
639 929
3818 2108
1080 2997
1282 2729
639 3254
4295 364
4709 2265
364 2012
2729 1274
1282 861
4672...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
0
1
1
1
1
1
2
2
2
3
3
3
3
3
4
4
4
4
5
5
5
5
5
5
5
6
6
7
7
7
7
8
8
8
8
9
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40...

result:

ok 5001 lines

Test #5:

score: 9
Accepted
time: 223ms
memory: 8192kb

input:

5000 5000
4234 3796
4234 497
3796 1415
1415 3546
3546 908
497 4964
908 1489
1489 2118
1489 834
3546 1954
4234 3880
908 3464
908 769
497 726
4234 276
1415 4773
769 282
1489 2640
2640 1264
4773 3
3 4786
1264 386
3464 321
1489 2281
3 1679
282 909
4234 750
321 1395
4786 4259
750 1208
1208 2763
497 4504
...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40...

result:

ok 5001 lines

Test #6:

score: 9
Accepted
time: 311ms
memory: 7404kb

input:

5000 5000
4738 201
201 2548
4738 4364
201 1021
1021 2767
1021 4263
4364 342
342 1051
342 3554
4263 108
342 4661
4364 4379
2548 3891
201 3439
2548 184
3554 1084
201 3931
4263 1798
4661 2099
4379 541
3554 2713
3439 3393
541 1996
4661 3765
2767 1833
3891 1301
1021 1063
184 4959
3439 4267
3891 2777
108 ...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
7
8
8
9
9
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
1...

result:

ok 5001 lines

Test #7:

score: 9
Accepted
time: 303ms
memory: 8628kb

input:

5000 5000
77 3249
3249 2845
3249 558
3249 1205
1205 822
558 807
77 2428
3249 560
560 1758
807 1729
2428 4308
822 2647
4308 803
822 3479
1758 3459
77 2119
1758 2128
3479 2762
3479 3601
4308 3621
3601 3214
4308 115
3601 2883
2119 2409
77 3867
4308 1282
803 861
1758 4847
3459 2862
2119 3435
1729 124
34...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
0
0
0
1
1
1
1
1
2
2
2
2
2
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
5
6
6
6
6
6
7
7
7
8
8
8
8
9
9
9
9
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
1...

result:

ok 5001 lines

Test #8:

score: 9
Accepted
time: 306ms
memory: 7624kb

input:

5000 5000
254 2905
254 3692
254 530
2905 3302
254 3965
3692 359
359 1575
530 2521
2521 4332
3302 139
359 2744
2521 4758
359 2648
1575 422
2905 1946
1575 3295
254 4103
3965 2870
2648 260
139 1274
2521 702
4332 1751
2744 4696
3302 3492
2870 261
2521 3483
4696 4380
530 3239
4332 2957
2870 315
2521 1199...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6...

result:

ok 5001 lines

Test #9:

score: 9
Accepted
time: 265ms
memory: 9012kb

input:

5000 5000
1490 3081
3081 3634
3634 477
3081 288
288 1112
1490 3843
288 2559
2559 3635
288 2310
2559 4986
1112 2889
2889 3104
288 1286
288 3085
477 2653
3104 2170
2889 3317
2559 3748
2559 3425
3635 3980
3980 1265
3843 44
1112 672
2310 2452
1490 2823
1265 696
2559 3140
696 2058
3748 2601
44 2853
2170 ...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
14
14
15
15
15
16
16
17
17
18
18
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
31
32
32
33
33
33
33
34
34
35
35
36
36
36
36
37
37
38
38
39
39
40
40
40
41
41
42
42
4...

result:

ok 5001 lines

Test #10:

score: 9
Accepted
time: 291ms
memory: 7880kb

input:

5000 5000
1602 2525
2525 2696
2525 2269
2696 3150
3150 2426
2525 775
2696 1288
2525 1104
2696 557
775 2958
2426 246
2525 4118
1602 3039
775 1420
2269 3934
2269 3376
2525 1121
3376 2566
557 2118
3934 2806
557 4524
2269 1955
2806 3162
4524 496
2566 3368
2118 1017
1602 1153
2806 2859
2118 2226
496 573
...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
1
1
2
2
3
3
3
3
4
4
4
4
4
5
5
5
5
5
6
6
6
6
7
7
7
7
7
7
8
8
8
8
9
9
9
9
9
9
10
10
10
10
11
11
11
11
11
12
12
12
13
13
13
13
14
14
14
14
15
15
15
16
16
17
17
17
18
18
18
19
19
19
20
20
20
21
21
22
22
22
23
23
23
24
24
24
24
24
25
25
25
26
26
26
27
27
27
28
28
...

result:

ok 5001 lines

Test #11:

score: 9
Accepted
time: 311ms
memory: 8652kb

input:

5000 5000
4578 81
4578 4163
81 4207
4163 442
4578 2090
4578 950
950 4490
442 750
4207 2755
442 831
950 2408
4578 2891
750 3636
750 1203
831 714
831 1011
2755 1949
750 2349
2755 4820
1203 2406
2349 2359
4578 1092
4820 4935
4163 2293
3636 3361
1011 2701
2755 3668
1203 1511
2891 1289
2701 2173
714 3853...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
6
6
6
6
5
5
5...

result:

ok 5001 lines

Subtask #2:

score: 0
Runtime Error

Test #12:

score: 0
Runtime Error

input:

200000 200000
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51...

output:

Unauthorized output

result:


Subtask #3:

score: 0
Runtime Error

Test #25:

score: 0
Runtime Error

input:

200000 200000
155284 18435
18435 57260
57260 88628
88628 170108
57260 126961
170108 72596
72596 46044
170108 28914
46044 177699
155284 143087
18435 161808
177699 107693
18435 74517
28914 77075
126961 116303
177699 26806
74517 43330
77075 188898
126961 45168
57260 93201
93201 198698
77075 36077
57260...

output:

Unauthorized output

result:


Subtask #4:

score: 0
Runtime Error

Test #37:

score: 0
Runtime Error

input:

200000 200000
124028 117993
117993 64181
124028 176900
64181 197782
124028 153477
153477 179542
64181 191368
197782 55523
64181 36078
153477 108486
117993 169125
179542 68449
124028 153826
124028 142937
36078 65258
36078 28508
68449 114673
191368 17655
197782 90991
176900 48570
191368 6324
153826 18...

output:

Unauthorized output

result:


Subtask #5:

score: 0
Runtime Error

Test #51:

score: 0
Runtime Error

input:

200000 200000
75490 97148
75490 176817
75490 80168
75490 73425
97148 38334
80168 199950
73425 5116
5116 154439
80168 90246
154439 5305
154439 101118
101118 28211
90246 91284
75490 103069
80168 85099
176817 55430
38334 31693
55430 28292
80168 163565
163565 196782
28211 194198
28292 163487
73425 30097...

output:

Unauthorized output

result: