UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213549#573. t2wangyaxu123Compile Error//C++1.6kb2024-11-12 20:35:422024-11-12 23:34:32

answer

#include<iostream>
#include<algorithm>
#include<stack> 
#include<cstring>
#include<queue>
#include<vector>
#include<map> 
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;
	
} 

详细

answer.code: In function 'int read()':
answer.code:29:20: error: 'getchar' was not declared in this scope
     char c=getchar();int x=0,f=1;\x0d
                    ^