QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#472456#4895. Lovely Dogszyxawa0 899ms41460kbC++141.7kb2024-07-11 16:33:432024-07-11 16:33:43

Judging History

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

  • [2024-07-11 16:33:43]
  • 评测
  • 测评结果:0
  • 用时:899ms
  • 内存:41460kb
  • [2024-07-11 16:33:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,d,u,v,t,now,sum[200001],a[200001],p[200001],mu[200001],g[200001],son[200001],siz[200001],ans[200001];
basic_string <int> G[200001],F[200001];
long long w,val[200001];
void dfs3(int x,int u,int h,int v){
	if(v){
		for(int i:F[a[x]]){
			w=val[i]/__gcd(val[i],1ll*a[x]);
			if(w<=n) now+=g[a[x]]*mu[i]*sum[w];
		}
		for(int i:F[a[x]]) sum[i]+=g[a[x]];
	}
	else{
		for(int i:F[a[x]]) sum[i]-=g[a[x]];
		for(int i:F[a[x]]){
			w=val[i]/__gcd(val[i],1ll*a[x]);
			if(w<=n) now-=g[a[x]]*mu[i]*sum[w];
		}
	}
	for(int y:G[x]) if(y!=u&&y!=h) dfs3(y,x,h,v);
}
void dfs2(int x,int u,int k){
	for(int y:G[x]) if(y!=u&&y!=son[x]) dfs2(y,x,0);
	if(son[x]) dfs2(son[x],x,1);
	dfs3(x,u,son[x],1),ans[x]+=now;
	if(!k) dfs3(x,u,0,0);
}
void dfs1(int x,int u){
	int v=a[x],mx=0;
	for(int i=1;i<=t&&p[i]*p[i]<=v;i++){
		if(v%p[i]==0){
			int cnt=0;
			while(v%p[i]==0) cnt++,v/=p[i];
			mx=max(mx,cnt);
		}
	}
	if(v>1) mx=max(mx,1);
	siz[x]=1,ans[x]=mx*2<=d,val[x]=1;
	for(int i=1;i<=d+1&&val[x]<=1ll*n*n;i++) val[x]*=x;
	for(int y:G[x]) if(y!=u) dfs1(y,x),ans[x]+=ans[y],siz[x]+=siz[y],siz[y]>siz[son[x]]&&(son[x]=y,0);
}
int main(){
	scanf("%d%d",&n,&d);
	for(int i=1;i<n;i++) scanf("%d%d",&u,&v),G[u]+=v,G[v]+=u;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	mu[1]=g[1]=1;
	for(int i=2;i<=n;i++){
		if(!p[i]) p[++t]=i,mu[i]=g[i]=-1;
		for(int j=1;j<=t&&i*p[j]<=n;j++){
			mu[i*p[j]]=-mu[i],g[i*p[j]]=-g[i],p[i*p[j]]=1;
			if(i%p[j]==0){mu[i*p[j]]=0;break;}
		}
	}
	for(int i=1;i<=n;i++) for(int j=i;j<=n;j+=i) F[j]+=i;
	dfs1(1,0),dfs2(1,0,1);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	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: 4ms
memory: 22268kb

input:

20 2
18 8
18 11
13 19
10 8
9 11
4 8
9 15
9 17
2 1
13 18
20 18
1 8
12 17
7 16
5 11
16 15
6 19
14 16
1 3
2 15 5 13 20 6 16 18 9 19 17 7 14 10 11 3 1 12 4 8

output:

14
1
1
1
0
1
0
10
2
1
4
1
3
1
0
0
1
5
1
0

result:

wrong answer 1st words differ - expected: '16', found: '14'

Subtask #2:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 7ms
memory: 22460kb

input:

2000 1
134 1468
867 1750
351 1220
1690 1888
1685 134
585 282
1142 643
206 271
260 1833
1987 770
1029 1667
322 1371
341 518
601 915
119 893
1933 1502
951 1785
1056 1630
1957 1208
96 55
1508 1212
331 427
505 151
1378 1486
1545 697
1459 629
202 997
180 1917
1638 1177
1244 1896
302 658
1433 1605
1318 19...

output:

-283
39
16
89
3
107
88
77
107
-5
73
113
103
18
10
120
16
1
10
89
41
13
99
41
43
116
116
15
44
-5
89
117
24
17
15
88
85
13
0
75
-7
60
16
120
10
36
30
-2
75
42
-2
89
58
0
8
21
87
75
100
17
12
99
78
10
77
100
-3
-2
8
1
7
0
70
118
59
59
98
29
7
3
0
40
71
99
17
46
70
-1
16
46
-1
71
72
115
5
8
64
32
63
1
...

result:

wrong answer 1st words differ - expected: '581', found: '-283'

Subtask #3:

score: 0
Time Limit Exceeded

Test #45:

score: 0
Time Limit Exceeded

input:

200000 20
117994 12616
53490 106425
103660 50033
132640 78252
58384 19939
69183 10015
39098 165030
179856 130356
65245 57831
18234 83378
4240 154896
177149 102260
4634 180087
132390 19627
98506 60775
1890 120740
87908 21917
41323 192721
181885 96684
69412 139951
9800 38301
59025 29879
186185 81402
1...

output:

143459
1
6
1
17
19
1
2
3
1
1
26
1
1
1
1
1
1
7
1
1
3
1
2
1
1
1
1
4
3
2
1
3
13
19
1
1
1
1
1
1
34
1
1
1
12
1
1
3
1
24
1
1
1
2
1
1
6
1
3
1
3
1
10
1
1
1
3
4
9
1
2
3
1
1
1
7
2
6
1
1
1
1
1
1
2
3
457
2
1
3
1
1
1
1
12
1
1
1
6
2
1
1
3
1
3
113
1
4
11
2
1
4
2
1
1
1
25
22
2
3
1
1
3
3
1
2
3
1
2
1
1
107
1
1
14
1
1...

result:


Subtask #4:

score: 0
Wrong Answer

Test #50:

score: 0
Wrong Answer
time: 347ms
memory: 40372kb

input:

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

output:

-31677
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

wrong answer 1st words differ - expected: '-44916', found: '-31677'

Subtask #5:

score: 0
Wrong Answer

Test #55:

score: 0
Wrong Answer
time: 336ms
memory: 40248kb

input:

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

output:

-71526
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

wrong answer 1st words differ - expected: '-44916', found: '-71526'

Subtask #6:

score: 0
Wrong Answer

Test #78:

score: 0
Wrong Answer
time: 156ms
memory: 26580kb

input:

50000 1
8097 41839
17674 41774
40520 8024
5786 38261
20664 43471
1217 49276
11185 40807
14186 25584
31704 14814
42333 41475
13053 39565
45938 30104
5826 39463
5031 10814
43784 6042
58 33849
42978 18978
36307 33276
34769 4351
27884 37532
27528 29431
29451 39345
10946 9667
19016 47269
7911 30103
10308...

output:

-5999
2413
2360
4409
775
4807
4787
3590
4632
4065
4970
5525
5386
3316
4756
4547
4850
4315
4523
4978
2911
2316
2135
4523
4753
4653
4731
-4
4756
4728
783
834
3563
2282
4928
4886
18
4958
4062
2207
4786
4887
4907
70
858
4961
4895
832
4746
4339
4890
4338
3116
852
2305
4856
4664
50
2270
4039
4608
857
-179...

result:

wrong answer 1st words differ - expected: '-9152', found: '-5999'

Subtask #7:

score: 0
Wrong Answer

Test #103:

score: 0
Wrong Answer
time: 899ms
memory: 41460kb

input:

200000 1
118863 188865
188022 168616
118976 119404
178852 33449
81624 40431
151228 160976
68943 136313
57200 117631
147789 139875
100240 55537
164811 145415
103548 186750
15010 168029
155731 107005
69836 1502
86171 122700
83448 131948
189162 94464
128210 2509
49724 183329
174782 192641
27687 71315
1...

output:

-94916
-475
12637
16200
15921
11078
17031
790
15571
15571
937
12608
17939
15886
11992
15703
17189
18706
17891
301
16230
17731
8069
12544
17300
489
18826
18080
15767
12826
18593
311
242
950
10871
12274
14787
990
17472
17357
14923
16904
17424
15424
12414
12699
17066
15866
11902
10919
11689
14970
1019
...

result:

wrong answer 1st words differ - expected: '-44916', found: '-94916'