UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213619#573. t2meixuanCompile Error//C++1.2kb2024-11-12 22:01:532024-11-12 23:57:38

answer

#include<bits/stdc++.h>
using namespace std;
map<int,int> mp[110000];
vector<pair<int,int> >e[110000];
int cnt[110000];
int add(int a,int b){
	if(mp[a].size()<mp[b].size())swap(a,b);
	for(auto v:mp[b]){
		mp[a][v.first]+=v.second;
	}
	return a;
}
void dfs(int u,int fa){	
//cout <<"aa  "<<u<<' '<<fa<<endl;
	for(auto v:e[u]){
		if(v.first==fa)continue;
		dfs(v.first,u);
	}

	for(auto v:e[u]){
		if(v.first==fa)continue;
		int tv=v.first,tw=v.second;
		mp[u][tw]++;
		for(auto tn:mp[tv]){
			mp[u][__gcd(tw,tn.first)]+=tn.second;
		}
	}
}
int dfs2(int u,int fa){
	int now=u;
	for(auto v:e[u]){
		if(v.first==fa)continue;
		now=add(now,dfs2(v.first,u));
	}
	return now;
} 
int main(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	int n,q;
	cin >>n>>q;
	for(int i=1;i<n;i++){
		int u,v,w;
		cin >>u>>v>>w;
		e[u].push_back(make_pair(v,w));
		e[v].push_back(make_pair(u,w));
	}
	dfs(1,0);
	int tnow=dfs2(1,0);
	for(auto v:mp[tnow]){
	//	cout <<v.first<<' '<<v.second<<endl;
		cnt[v.first]=v.second;
	}
//	cout <<endl;
	for(int i=1;i<=n;i++){
	//	cout <<cnt[i]<<' ';
		for(int j=2*i;j<=n;j+=i){
			cnt[i]+=cnt[j];
		}
	}
//	int q;
//	cin >>q;
	while(q--){
		int t;
		cin >>t;
		cout <<cnt[t]<<'\n';
	}
}

详细

answer.code: In function 'int add(int, int)':
answer.code:8:11: error: 'v' does not name a type
  for(auto v:mp[b]){\x0d
           ^
answer.code:11:2: error: expected ';' before 'return'
  return a;\x0d
  ^
answer.code:11:2: error: expected primary-expression before 'return'
answer.code:11:2: error: expected ';' before 'return'
answer.code:11:2: error: expected primary-expression before 'return'
answer.code:11:2: error: expected ')' before 'return'
answer.code: In function 'void dfs(int, int)':
answe...