QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20236 | #2426. The Xana coup | 19ty02# | 0 | 39ms | 15384kb | C++20 | 960b | 2022-02-15 07:42:32 | 2022-05-03 09:21:49 |
Judging History
answer
#include<cstdio>
#include<iostream>
using namespace std;
const int N=1e5+10,inf=1e9;
int n,tot,h[N];
struct edge{
int to,nxt;
}e[N<<1];
void add(int u,int v){
e[++tot]=(edge){v,h[u]};
h[u]=tot;
}
int a[N],f[N][2][2];
void dfs(int u,int fa){
if(a[u])f[u][1][1]=f[u][0][0]=inf;
else f[u][1][0]=f[u][0][1]=inf;
for(int i=h[u];i;i=e[i].nxt){
int v=e[i].to;
if(v==fa)continue;
dfs(v,u);
int tmp=f[u][1][0];
f[u][1][0]=min(f[u][1][0]+f[v][0][1],f[u][1][1]+f[v][1][1]);
f[u][1][1]=min(f[u][1][1]+f[v][0][1],tmp+f[v][1][1]);
tmp=f[u][0][0];
f[u][0][0]=min(f[u][0][0]+f[v][0][0],f[u][0][1]+f[v][1][0]);
f[u][0][1]=min(f[u][0][1]+f[v][0][0],tmp+f[v][1][0]);
}
f[u][1][0]++;f[u][1][1]++;
}
int main(){
scanf("%d",&n);
for(int i=1,u,v;i<n;i++){
scanf("%d%d",&u,&v);
add(u,v);add(v,u);
}
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
dfs(1,0);
printf("%d",min(f[1][0][0],f[1][1][0]));
}
/*
1
1
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Accepted
time: 3ms
memory: 5836kb
input:
5 1 2 1 3 2 4 2 5 0 1 0 1 1
output:
4
result:
ok single line: '4'
Test #2:
score: -0
Wrong Answer
time: 4ms
memory: 5836kb
input:
5 1 2 2 3 3 4 4 5 0 1 1 1 1
output:
1000000001
result:
wrong answer 1st lines differ - expected: 'impossible', found: '1000000001'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #8:
score: 15
Accepted
time: 3ms
memory: 5812kb
input:
33 6 4 25 31 28 6 9 12 16 22 27 3 11 26 27 19 28 15 10 15 23 20 11 14 28 24 24 5 33 26 8 9 4 14 1 7 22 20 27 17 13 28 19 32 23 29 10 19 18 22 21 7 21 9 30 20 2 5 29 31 31 4 21 26 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 0 0 1
output:
13
result:
ok single line: '13'
Test #9:
score: 0
Accepted
time: 0ms
memory: 5812kb
input:
39 26 9 26 14 28 25 18 38 6 15 1 28 23 31 20 3 17 31 22 1 10 16 20 29 35 18 18 25 7 36 24 26 2 32 13 8 17 39 2 19 13 36 4 30 24 10 22 36 16 11 18 33 34 6 27 20 5 20 15 12 8 2 28 3 35 31 15 24 29 21 21 30 26 38 37 27 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 0 1
output:
19
result:
ok single line: '19'
Test #10:
score: -15
Wrong Answer
time: 3ms
memory: 5896kb
input:
40 5 16 2 4 30 27 15 39 8 3 14 16 3 23 34 2 35 27 26 40 12 30 36 21 25 26 10 7 5 3 7 15 14 17 29 33 13 40 21 1 12 19 38 22 29 9 37 32 7 17 13 33 3 28 19 40 11 26 37 34 40 6 20 6 6 18 25 38 24 21 18 34 17 21 35 24 31 36 1 1 0 1 1 0 0 0 0 0 1 0 1 1 0 0 1 0 1 1 0 1 0 1 0 1 1 0 1 1 1 0 1 0 0 0 0 0 0 1
output:
-1294967274
result:
wrong answer 1st lines differ - expected: '21', found: '-1294967274'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 10
Accepted
time: 39ms
memory: 15384kb
input:
99481 19117 19116 39650 39651 69914 69913 6831 6830 32628 32629 47585 47586 9962 9963 43561 43562 65038 65037 89192 89191 55315 55314 67819 67820 62853 62852 37838 37839 13481 13482 79553 79552 13649 13648 42022 42023 40952 40953 53979 53980 31280 31281 52472 52473 4690 4691 659 660 34413 34412 6409...
output:
49772
result:
ok single line: '49772'
Test #15:
score: -10
Wrong Answer
time: 37ms
memory: 15276kb
input:
98273 46112 46113 46912 46913 74330 74329 44926 44925 45873 45874 67146 67145 5397 5396 2561 2560 82735 82736 94041 94040 26762 26761 24535 24534 29483 29482 36116 36115 6390 6391 84795 84796 21112 21113 78994 78993 48299 48298 174 173 15717 15716 93544 93545 32500 32499 177 176 639 638 46383 46384 ...
output:
1000048881
result:
wrong answer 1st lines differ - expected: 'impossible', found: '1000048881'
Subtask #5:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 20ms
memory: 7408kb
input:
89310 15556 57000 19677 35349 9259 25855 43787 63864 64941 54366 20524 82369 74758 65181 26075 75148 76809 29415 64603 77798 60446 1000 86747 70876 65376 11036 2506 88761 45097 50529 45097 83913 33059 79620 54248 11298 37025 18974 7782 83068 63113 70024 69926 54332 21966 1572 79769 72650 24200 8844 ...
output:
-1672747291
result:
wrong answer 1st lines differ - expected: 'impossible', found: '-1672747291'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%