UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213622#573. t2bigsmart210370ms7000kbC++11591b2024-11-12 22:04:052024-11-12 23:57:49

answer

#include<iostream>
#include<vector>
using namespace std;
vector<pair<int,int> > tree[112310];
int a[114151];
int k;
int dfs(int p,int val){
	if(tree[p].empty()){
		return a[p] = val;
	}
	int sum = 0;
	bool f = 1;
	for(auto v:tree[p]){
		if(v.second%k==0){
			f = 0;
			sum+=dfs(v.first,val+1);
		}
	}
	if(f){
		return val;
	}
	else{
		return sum;
	}
}
int main(){
	int n,q;
	cin>>n>>q;
	for(int i=1;i<n;i++){
		int u,v,x;
		cin>>u>>v>>x;
		tree[u].push_back(make_pair(v,x));
	}
	for(int i=1;i<=q;i++){
		cin>>k;
		cout<<dfs(1,0)*2<<endl;
	}
	return 0;
}

Details

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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:

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: '2', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 179ms
memory: 7000kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
14
0
0
0
0
0
0
0
0
14
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
14
0
0
2...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 191ms
memory: 6996kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
18
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: '8', found: '0'