QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#410787 | #6317. XOR Tree Path | grass8cow# | AC ✓ | 31ms | 16664kb | C++17 | 854b | 2024-05-14 14:55:00 | 2024-05-14 14:55:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,a[101000];
#define pb push_back
vector<int>g[100100];
int dp[101000][2];
const int I=1e9;
void ad(int &x,int y){x=max(x,y);}
void dfs(int x,int f){
bool os=0;
for(int v:g[x])if(v!=f)dfs(v,x),os=1;
if(!os){
for(int o=0;o<2;o++)
dp[x][o]=(a[x]^o);
return;
}
int t[2]={0,-I};
for(int v:g[x])if(v!=f){
int t2[2]={-I,-I};
for(int i=0;i<2;i++)for(int j=0;j<2;j++)
ad(t2[i^j],t[i]+dp[v][j]);
t[0]=t2[0],t[1]=t2[1];
}
for(int o=0;o<2;o++)dp[x][o]=t[o]+(a[x]^o);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1,u,v;i<n;i++)
scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
dfs(1,0);
printf("%d",max(dp[1][0],dp[1][1]));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6124kb
input:
5 1 0 0 1 0 1 2 1 3 3 4 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 6144kb
input:
6 1 1 0 0 1 0 3 1 2 5 1 2 4 1 2 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 6160kb
input:
9 1 0 1 0 1 0 1 0 1 2 9 1 2 6 9 3 8 4 5 5 9 2 8 7 8
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 21ms
memory: 9376kb
input:
73537 0 0 0 0 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 1 0 0 1 0 0 0 1 1 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 ...
output:
56486
result:
ok 1 number(s): "56486"
Test #5:
score: 0
Accepted
time: 0ms
memory: 6312kb
input:
4440 1 1 1 1 1 0 1 1 1 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 1 1 0 1 1 1 1 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 0 0 0 1 0 0...
output:
3419
result:
ok 1 number(s): "3419"
Test #6:
score: 0
Accepted
time: 14ms
memory: 8540kb
input:
55025 1 0 1 0 0 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 1 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 0 1 1 0 1 1 1 1 1 0 0 0 0 1 1 0 ...
output:
42221
result:
ok 1 number(s): "42221"
Test #7:
score: 0
Accepted
time: 21ms
memory: 8740kb
input:
59260 1 1 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 ...
output:
45452
result:
ok 1 number(s): "45452"
Test #8:
score: 0
Accepted
time: 12ms
memory: 8136kb
input:
48580 1 1 1 1 1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 0 0 1 1 0 1 0 0 1 1 1 0 1 0 1 0 1 1 1 0 0 1 0 1 0 ...
output:
37287
result:
ok 1 number(s): "37287"
Test #9:
score: 0
Accepted
time: 18ms
memory: 10584kb
input:
100000 1 1 0 1 1 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 0 0 1 0 0 1 1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1...
output:
76831
result:
ok 1 number(s): "76831"
Test #10:
score: 0
Accepted
time: 30ms
memory: 10484kb
input:
100000 1 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0...
output:
76692
result:
ok 1 number(s): "76692"
Test #11:
score: 0
Accepted
time: 25ms
memory: 10528kb
input:
100000 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 0 0 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1 1 1 0 0 1 0 0 0 0 1 0 0 1 1 1 1 0...
output:
76715
result:
ok 1 number(s): "76715"
Test #12:
score: 0
Accepted
time: 1ms
memory: 5952kb
input:
2 1 0 1 2
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 0
Accepted
time: 1ms
memory: 5948kb
input:
2 0 0 1 2
output:
2
result:
ok 1 number(s): "2"
Test #14:
score: 0
Accepted
time: 2ms
memory: 6172kb
input:
3 0 0 0 1 2 1 3
output:
2
result:
ok 1 number(s): "2"
Test #15:
score: 0
Accepted
time: 4ms
memory: 9352kb
input:
30258 1 1 0 0 0 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 0 0 0 0 0 1 1 ...
output:
15162
result:
ok 1 number(s): "15162"
Test #16:
score: 0
Accepted
time: 15ms
memory: 12864kb
input:
63626 1 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 0 0 1 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 0 0 0 1 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 0 0 0 1 0 1 1 0 1 1 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 ...
output:
31871
result:
ok 1 number(s): "31871"
Test #17:
score: 0
Accepted
time: 31ms
memory: 16664kb
input:
100000 0 0 1 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 1 0 1 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0 1 0 1...
output:
50029
result:
ok 1 number(s): "50029"
Test #18:
score: 0
Accepted
time: 2ms
memory: 6152kb
input:
702 1 1 0 0 0 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 0 0 0 0 0 1 1 0 ...
output:
532
result:
ok 1 number(s): "532"
Test #19:
score: 0
Accepted
time: 0ms
memory: 6140kb
input:
555 1 0 1 1 1 1 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 1 0 1 0 0 1 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 1 0 ...
output:
424
result:
ok 1 number(s): "424"
Test #20:
score: 0
Accepted
time: 2ms
memory: 6088kb
input:
81 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 0 1 1 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 1 0 0 1 1 1 1 1 31 11 53 51 76 10 17 12 68 10 43 36 56 79 81 55 56 68 81 27 50 18 64 29 36 8 59 4 52 6 7 4 54 5 16 49 56 38 41 24 33 25 52 32 71 14 5...
output:
57
result:
ok 1 number(s): "57"
Test #21:
score: 0
Accepted
time: 0ms
memory: 6116kb
input:
654 0 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1 0 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 1 0 1 1 1 1 0 ...
output:
503
result:
ok 1 number(s): "503"
Test #22:
score: 0
Accepted
time: 2ms
memory: 6164kb
input:
721 1 0 0 1 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 1 1 1 0 0 1 1 1 0 1 0 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 0 1 1 1 1 1 ...
output:
557
result:
ok 1 number(s): "557"
Test #23:
score: 0
Accepted
time: 3ms
memory: 7480kb
input:
30258 1 1 0 0 0 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 0 0 0 0 0 1 1 ...
output:
30258
result:
ok 1 number(s): "30258"
Test #24:
score: 0
Accepted
time: 9ms
memory: 8084kb
input:
43363 0 1 0 1 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 0 1 0 1 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 1 0 0 1 ...
output:
43363
result:
ok 1 number(s): "43363"
Test #25:
score: 0
Accepted
time: 15ms
memory: 10460kb
input:
100000 0 0 0 0 1 1 1 0 1 1 1 0 0 1 1 1 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 0 1 1 1 1 0 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 1 0 1 0 0 0...
output:
100000
result:
ok 1 number(s): "100000"
Test #26:
score: 0
Accepted
time: 0ms
memory: 6216kb
input:
20 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 1 1 0 1 20 17 18 10 11 5 19 5 12 6 18 2 13 8 18 8 13 13 15 1 3 5 11 14 15 3 16 9 17 7 19 4 12 4 16 7 15
output:
13
result:
ok 1 number(s): "13"
Test #27:
score: 0
Accepted
time: 2ms
memory: 6120kb
input:
8 1 0 0 1 0 1 0 0 3 5 3 8 1 2 6 8 3 4 1 6 7 8
output:
6
result:
ok 1 number(s): "6"