UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213602#573. t2honghaojinCompile Error//C++111.1kb2024-11-12 21:35:522024-11-12 23:54:22

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll=long long;
const int N=1e5+10,D=100;

#define add(u,v,w) \
	to[++cnt]=v,wt[cnt]=w,nt[cnt]=hd[u],hd[u]=cnt, \
	to[++cnt]=u,wt[cnt]=w,nt[cnt]=hd[v],hd[v]=cnt
#define sqr(x) (x)*(x)

int hd[N],to[N<<1],nt[N<<1],wt[N<<1],cnt;
ll dp[N][D+10],s[N][D+10],s2[N][D+10];
void dfs(int u,int fa){
	std::fill(s[u]+1,s[u]+D+1,1);
	for(int e=hd[u];e;e=nt[e]){
		int v=to[e],w=wt[e];
		if(v==fa)continue;
		dfs(v,u);
		for(int i=1;i<=D;++i){
			if(!(w%i)){
				s[u][i]+=s[v][i],dp[u][i]+=s[v][i];
				s2[u][i]+=sqr(s[v][i]);
			}
			dp[u][i]+=dp[v][i];
		}
	}
//	cout<<'\n'<<u<<'\n';
//	for(int i=1;i<=5;++i)cout<<dp[u][i]<<" \n"[i==5];
//	for(int i=1;i<=5;++i)cout<<s[u][i]<<" \n"[i==5];
//	for(int i=1;i<=5;++i)cout<<s2[i]<<" \n"[i==5];
	for(int i=1;i<=D;++i)
		dp[u][i]+=(sqr(s[u][i]-1)-s2[u][i])/2;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,q,d;
	cin>>n>>q;
	for(int i=1,u,v,w;i<n;++i)
		cin>>u>>v>>w,add(u,v,w);
	dfs(1,0);
	while(q--)
		cin>>d,cout<<dp[1][d]<<'\n';
	return 0;
}

详细

answer.code: In function 'int main()':
answer.code:36:2: error: 'ios' has not been declared
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\x0d
  ^