ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213615 | #573. t2 | ckliang | 0 | 0ms | 0kb | C++11 | 979b | 2024-11-12 21:52:14 | 2024-11-12 23:57:07 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100,maxn=1e5+1;
vector<pair<int,int> >G[N];
map<int,int> t[N][2];
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
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
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:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
100000 100000 73595 40695 76 13615 40695 96 65545 13615 84 19391 13615 76 2353 73595 27 26730 40695 ...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
input:
100000 100000 73595 40695 12816 13615 73595 81821 65545 40695 75866 19391 65545 1165 2353 73595 3737...