ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214624 | #2376. 树与异或 | void_user | 30 | 72ms | 3876kb | C++11 | 1.0kb | 2024-11-20 20:55:49 | 2024-11-20 23:06:57 |
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;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 24ms
memory: 3876kb
input:
1000 994 780089107 4670366 871010085 73730768 526852049 572589363 885190993 1049357301 450850404 460...
output:
503748432
result:
ok 1 number(s): "503748432"
Test #2:
score: 10
Accepted
time: 24ms
memory: 3872kb
input:
1000 999 26885995 181771373 378079250 245122183 660787775 479226046 575400611 257120086 214404794 48...
output:
301019013
result:
ok 1 number(s): "301019013"
Test #3:
score: 10
Accepted
time: 24ms
memory: 3876kb
input:
1000 994 978408146 31636243 945016735 512129400 92881624 689719983 649699545 964802847 100094796 941...
output:
250985726
result:
ok 1 number(s): "250985726"
Test #4:
score: 0
Time Limit Exceeded
input:
100000 99994 194640838 777315353 114710204 754050649 372592717 210279787 542056883 638262010 7998293...
output:
result:
Test #5:
score: 0
Time Limit Exceeded
input:
100000 100000 458877901 215980825 777376132 863774865 34430451 828397116 94813690 931300514 10548367...
output:
result:
Test #6:
score: 0
Time Limit Exceeded
input:
100000 99991 56406146 757409402 876799234 573444553 883023109 326033134 328116703 623771278 41269529...
output:
result:
Test #7:
score: 0
Runtime Error
input:
1000000 999998 814298729 663807029 628693441 45635199 148428014 913833778 1034283337 600802841 58045...
output:
result:
Test #8:
score: 0
Runtime Error
input:
1000000 999993 112899321 425466951 471078924 857561298 449437156 710041336 1033281580 23390934 44420...
output:
result:
Test #9:
score: 0
Runtime Error
input:
1000000 1000000 273043260 1042513348 30746190 864557483 187812119 562837674 263192174 364182254 3537...
output:
result:
Test #10:
score: 0
Runtime Error
input:
1000000 999995 83067658 1064735371 623243759 757522311 539363923 924297206 75317137 543750195 822898...