UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214622#2376. 树与异或void_userCompile Error//C++1.0kb2024-11-20 20:54:372024-11-20 23:06:45

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k=2,c[100005],dp[100005][25],fa[100005],q;
vector<int>a[100005];
void dfs1(int now){
	for(int i:a[now]){
		if(fa[now]==i)continue;
		fa[i]=now;
		dfs1(i);
		for(int j=1;j<=k;j++){
			dp[now][j]^=dp[i][j-1];
		}
	}
	return;
} 
void dfs2(int now){
	for(int i:a[now]){
		if(fa[now]==i)continue;
		for(int j=k;j>=2;j--){
			dp[i][j]^=dp[i][j-2];
		}
		for(int j=1;j<=k;j++){
			dp[i][j]^=dp[now][j-1];
		}
		dfs2(i);
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	for(int i=1;i<=n;i++)dp[i][0]=c[i];
	int sum=0;
	for(int i=1;i<=q;i++){
		int x,y;
		cin>>x>>y;
		for(int i=1;i<=n;i++)dp[i][1]=dp[i][2]=0;
		dp[x][0]=y;
		dfs1(1);
		dfs2(1);
		int ans=0;
		for(int j=0;j<=k;j++)ans^=dp[x][j]; 
		sum=(sum+((ans*i)%1000000007)*i)%1000000007;
	}
	cout<<sum;
	return 0;
}

详细

answer.code: In function 'void dfs1(long long int)':
answer.code:7:12: error: range-based 'for' loops are not allowed in C++98 mode
  for(int i:a[now]){\x0d
            ^
answer.code: In function 'void dfs2(long long int)':
answer.code:18:12: error: range-based 'for' loops are not allowed in C++98 mode
  for(int i:a[now]){\x0d
            ^
answer.code: In function 'int main()':
answer.code:54:18: warning: name lookup of 'i' changed [enabled by default]
   sum=(sum+((ans*i)%1000000007)*i)%1000000007;\x0d...