UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213616#573. t2ckliang0573ms91496kbC++11974b2024-11-12 21:56:232024-11-12 23:57:17

answer

#include<bits/stdc++.h>

using namespace std;
const int N=1e5+100,maxn=110;
vector<pair<int,int> >G[N];
int t[N][2][maxn];
int n,q;
void dfs(int u,int f)
{
	int v,w;
	for( auto e:G[u] )
	{
		v=e.first;
		w=e.second;
		if( v==f )continue;
		dfs(v,u);
		for( int i=1 ; i<maxn ; i++ )
		{
			t[u][1][i]+=t[v][1][i]+t[v][0][i];
			if( w%i==0 )
			{
				t[u][1][i]+=t[u][0][i]*(t[v][0][i]+1);
				t[u][0][i]+=t[v][0][i]+1;
			//	cout<<u<<" "<<v<<" "<<i<<endl;
			//	cout<<t[u][1][i]<<" "<<t[u][0][i]<<" "<<t[v][1][i]<<" "<<t[v][0][i]<<endl<<endl;
			}
		//	else t[u][1][i]+=t[v][0][i];
		}
	}
}
int main()
{
	cin>>n>>q;
	int u,v,w;
	for( int i=1 ; i<n ; i++ )
	{
		cin>>u>>v>>w;
		G[u].push_back(make_pair(v,w));
		G[v].push_back(make_pair(u,w));
	}
	dfs(1,0);
	while(q--)
	{
		cin>>u;
	//	cout<<t[1][1][u]<<" "<<t[1][0][u]<<endl; 
		cout<<t[1][1][u]+t[1][0][u]<<endl; 
	}
	return 0;
} 
/*
4 3
1 2 4
2 3 4
2 4 3
4
1
2
*/

详细

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 3624kb

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
58
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
0
1
0
1
1
0
20
1
1
0
6
0
0
1

result:

wrong answer 6th words differ - expected: '0', found: '58'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 291ms
memory: 91444kb

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:

wrong answer 20th words differ - expected: '4999950000', found: '704982704'

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 282ms
memory: 91496kb

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
0
0
0
0
0
1035
2833
0
704982704
0
0
1294
6056
2221
4398
1587
4978...

result:

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