UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213605#573. t2honghaojin301929ms259496kbC++111.1kb2024-11-12 21:37:592024-11-12 23:54:56

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll=long long;
const int N=1e5+10,D=100;

#define add(u,v,w) \
	to[++cnt]=v,wt[cnt]=w,nt[cnt]=hd[u],hd[u]=cnt, \
	to[++cnt]=u,wt[cnt]=w,nt[cnt]=hd[v],hd[v]=cnt
#define sqr(x) (x)*(x)

int hd[N],to[N<<1],nt[N<<1],wt[N<<1],cnt;
ll dp[N][D+10],s[N][D+10],s2[N][D+10];
void dfs(int u,int fa){
	std::fill(s[u]+1,s[u]+D+1,1);
	for(int e=hd[u];e;e=nt[e]){
		int v=to[e],w=wt[e];
		if(v==fa)continue;
		dfs(v,u);
		for(int i=1;i<=D;++i){
			if(!(w%i)){
				s[u][i]+=s[v][i],dp[u][i]+=s[v][i];
				s2[u][i]+=sqr(s[v][i]);
			}
			dp[u][i]+=dp[v][i];
		}
	}
//	cout<<'\n'<<u<<'\n';
//	for(int i=1;i<=5;++i)cout<<dp[u][i]<<" \n"[i==5];
//	for(int i=1;i<=5;++i)cout<<s[u][i]<<" \n"[i==5];
//	for(int i=1;i<=5;++i)cout<<s2[i]<<" \n"[i==5];
	for(int i=1;i<=D;++i)
		dp[u][i]+=(sqr(s[u][i]-1)-s2[u][i])/2;
}
int main(){
	std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,q,d;
	cin>>n>>q;
	for(int i=1,u,v,w;i<n;++i)
		cin>>u>>v>>w,add(u,v,w);
	dfs(1,0);
	while(q--)
		cin>>d,cout<<dp[1][d]<<'\n';
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 30
Accepted
time: 0ms
memory: 1400kb

input:

50 50
48 29 49788
47 48 31142
35 48 28665
10 35 23889
39 35 6411
50 39 66666
43 35 27629
46 10 49173...

output:

2
1
0
0
0
2
0
0
0
0
0
0
1
10
0
0
1
0
0
2
0
1
0
2
0
0
0
0
0
2
0
0
0
0
2
0
0
0
1
0
0
1
0
2
1
2
0
0
0
0

result:

ok 50 tokens

Test #2:

score: -30
Wrong Answer
time: 0ms
memory: 1400kb

input:

50 50
48 29 36145
47 29 82496
35 47 66171
10 47 40597
39 48 64355
50 48 98687
43 39 15472
46 35 3729...

output:

0
0
0
4
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
1
0
13
0
1
1
0
1
1
0
20
1
1
0
6
0
0
1

result:

wrong answer 37th words differ - expected: '0', found: '1'

Subtask #2:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 184ms
memory: 259420kb

input:

100000 100000
73595 40695 76
13615 40695 96
65545 13615 84
19391 13615 76
2353 73595 27
26730 40695 ...

output:

12815
1065
2028
53298
627586
19060
4345
1010
16097
1032
1044
1054
3191
16097
1055
627586
19060
978
9...

result:

ok 100000 tokens

Test #12:

score: 0
Accepted
time: 162ms
memory: 259472kb

input:

100000 100000
73595 40695 70
13615 73595 52
65545 73595 51
19391 73595 72
2353 19391 18
26730 13615 ...

output:

975
1028
15852
1040
15852
5571
23908
49914
1010
15852
646494
12387
4999950000
20056
2104
4999950000
...

result:

ok 100000 tokens

Test #13:

score: 0
Accepted
time: 170ms
memory: 259384kb

input:

100000 100000
73595 40695 64
13615 40695 61
65545 13615 71
19391 65545 15
2353 19391 9
26730 19391 4...

output:

1041
2062
14285
23281
49485
12419
996
1018
1011
19672
19672
1036
23281
3195
4999950000
12419
1018
20...

result:

ok 100000 tokens

Test #14:

score: 0
Accepted
time: 193ms
memory: 259368kb

input:

100000 100000
73595 40695 58
13615 73595 70
65545 40695 38
19391 13615 58
2353 13615 47
26730 40695 ...

output:

23392
993
1036
13972
5412
1022
19503
3237
48221
23392
981
958486
1004
980
23392
993
48221
1020
980
1...

result:

ok 100000 tokens

Test #15:

score: 0
Accepted
time: 191ms
memory: 259356kb

input:

100000 100000
73595 40695 52
13615 40695 26
65545 73595 58
19391 40695 1
2353 13615 38
26730 13615 9...

output:

1021
48268
4999950000
998
2011
94940
1049
19311
19311
33716
48268
15508
2124
1040
985
15508
8140
482...

result:

ok 100000 tokens

Test #16:

score: 0
Accepted
time: 181ms
memory: 259340kb

input:

100000 100000
73595 40695 46
13615 73595 35
65545 40695 25
19391 13615 97
2353 40695 76
26730 65545 ...

output:

12645
997
1042
4999950000
1060
23020
4222
974
5631
19302
2078
1030
48335
2033
1002
1986
1018
6806
19...

result:

ok 100000 tokens

Test #17:

score: 0
Accepted
time: 185ms
memory: 259436kb

input:

100000 100000
73595 40695 40
13615 40695 91
65545 73595 45
19391 73595 40
2353 40695 67
26730 2353 4...

output:

9577
5383
23807
997
941
1013
19428
1003
95552
1024
49914
12451
2082
1109
49914
95552
49914
499995000...

result:

ok 100000 tokens

Test #18:

score: 0
Accepted
time: 185ms
memory: 259440kb

input:

100000 100000
73595 40695 34
13615 40695 100
65545 13615 12
19391 65545 83
2353 65545 58
26730 73595...

output:

4999950000
4416
2028
94412
4999950000
14337
1002
12327
23226
1038
6629
998
5505
1059
14337
2064
1042...

result:

ok 100000 tokens

Test #19:

score: 0
Accepted
time: 161ms
memory: 259496kb

input:

100000 100000
73595 40695 28
13615 73595 56
65545 40695 79
19391 13615 26
2353 65545 96
26730 65545 ...

output:

1031
93090
15639
3190
19477
1041
32364
12280
14143
47814
3110
416410
32364
22889
19477
4999950000
49...

result:

ok 100000 tokens

Test #20:

score: 0
Accepted
time: 153ms
memory: 259256kb

input:

100000 100000
73595 40695 22
13615 40695 65
65545 13615 99
19391 40695 22
2353 73595 87
26730 19391 ...

output:

33139
4999950000
3015
33139
91207
2093
944
1051
1006
1009
91207
15171
5538
33139
1031
2021
1018
9120...

result:

ok 100000 tokens

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 164ms
memory: 259120kb

input:

100000 100000
73595 40695 12816
13615 73595 81821
65545 40695 75866
19391 65545 1165
2353 73595 3737...

output:

0
2270
96901
0
2085
1584
4228
9112
2
0
0
0
0
1035
2833
0
4999950000
0
0
1294
6056
2221
4398
1587
497...

result:

wrong answer 1st words differ - expected: '8', found: '0'