ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213551 | #573. t2 | wangyaxu123 | 0 | 3225ms | 245372kb | C++11 | 1.5kb | 2024-11-12 20:36:55 | 2024-11-12 23:36:32 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,inf=1e9,mod=10007;
int n,m,pos=0,head[N],fa[N],que[N],sh[N],tto[N],sum=0,f[N];
int vis[N];
map<int,int> d[N];
int gcd(int a,int b){
if(!b)
return a;
return gcd(b,a%b);
}
struct mm{
int to,next,c;
}e[N<<1];
void add(int u,int v,int c){
pos++;
e[pos].to=v;
e[pos].c=c;
e[pos].next=head[u];
head[u]=pos;
}
inline int read(){
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
void dfs(int x,int f,int la){
fa[x]=f;
sh[x]=la;
for(int i=head[x];i;i=e[i].next){
int to=e[i].to;
if(to==f)
continue;
tto[x]=to;
dfs(to,x,e[i].c);
}
}
void dfs1(int x,int f){
for(int i=head[x];i;i=e[i].next){
int to=e[i].to;
if(to==f)
continue;
dfs1(to,x);
}
if(!tto[x]){
d[fa[x]][sh[x]]=1;
return;
}
d[fa[x]][sh[x]]=1;
for(int i=1;i<=1e5;i++){
d[fa[x]][gcd(sh[x],i)]+=d[x][i];
}
}
void dfs2(int x,int ff){
for(int i=1;i<=1e5;i++)
f[i]+=d[x][i];
for(int i=head[x];i;i=e[i].next){
int to=e[i].to;
if(to==ff)
continue;
dfs2(to,x);
}
}
int main(){
n=read();
m=read();
for(int i=1;i<n;i++){
int u=read(),v=read(),c=read();
add(u,v,c);
add(v,u,c);
}
dfs(1,0,0);
dfs1(1,0);
dfs2(1,0);
for(int i=1;i<=m;i++){
int k=read(),ans=0;
for(int j=1;j*k<=1e5;j++){
ans+=f[j*k];
}
cout<<ans<<'\n';
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 30
Accepted
time: 1592ms
memory: 245372kb
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: 1633ms
memory: 245372kb
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 2 1 0 13 0 0 1 0 1 1 0 17 1 1 0 6 0 0 1
result:
wrong answer 32nd words differ - expected: '3', found: '2'
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...