QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20075 | #2426. The Xana coup | Appleblue17# | 0 | 106ms | 20696kb | C++20 | 1.3kb | 2022-02-14 17:35:24 | 2022-05-03 09:01:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long N=1e5+5,INF=1e15;
struct nod{
long long to,nxt;
}e[N*2];
long long head[N],cnt;
void add(long long u,long long v){
e[++cnt]=(nod){v,head[u]};
head[u]=cnt;
}
long long n;
long long w[N];
long long dp[N][2][2],tmp[2][2];
void dfs(long long u,long long fa){
dp[u][0][w[u]]=0,dp[u][1][w[u]]=INF;
dp[u][0][w[u]^1]=INF,dp[u][1][w[u]^1]=1;
for(long long i=head[u];i;i=e[i].nxt){
long long v=e[i].to;
if(v==fa) continue;
dfs(v,u);
for(long long a=0;a<2;a++)
for(long long b=0;b<2;b++)
tmp[a][b]=INF;
for(long long a=0;a<2;a++){
for(long long b=0;b<2;b++){
for(long long c=0;c<2;c++){
for(long long d=0;d<2;d++){
if(b^c==1) tmp[a^d][b]=min(tmp[a^d][b],dp[u][a][b]+dp[v][c][d]);
}
}
}
}
for(long long a=0;a<2;a++)
for(long long b=0;b<2;b++)
dp[u][a][b]=tmp[a][b];
}
// cout<<u<<": "<<dp[u][0][0]<<"/"<<dp[u][0][1]<<" "<<dp[u][1][0]<<"/"<<dp[u][1][1]<<endl;
}
int main(){
cin>>n;
for(long long i=1;i<=n-1;i++){
long long u,v;
cin>>u>>v;
add(u,v),add(v,u);
}
for(long long i=1;i<=n;i++) cin>>w[i];
dfs(1,0);
long long ans=min(dp[1][1][0],dp[1][1][1]);
if(ans>=INF) puts("impossible");
else cout<<ans;
}
详细
Subtask #1:
score: 0
Accepted
Test #1:
score: 0
Accepted
time: 3ms
memory: 7612kb
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
Accepted
time: 1ms
memory: 5708kb
input:
5 1 2 2 3 3 4 4 5 0 1 1 1 1
output:
impossible
result:
ok single line: 'impossible'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #3:
score: 0
Wrong Answer
time: 4ms
memory: 7740kb
input:
17 2 7 3 17 9 16 15 8 6 13 7 10 12 17 12 4 1 11 7 15 3 14 11 17 8 17 1 5 13 7 8 16 0 1 1 0 1 0 0 0 1 0 0 0 0 1 1 0 1
output:
9
result:
wrong answer 1st lines differ - expected: '8', found: '9'
Subtask #3:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 2ms
memory: 7660kb
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:
14
result:
wrong answer 1st lines differ - expected: '13', found: '14'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 106ms
memory: 20696kb
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:
49892
result:
wrong answer 1st lines differ - expected: '49772', found: '49892'
Subtask #5:
score: 0
Wrong Answer
Test #17:
score: 40
Accepted
time: 57ms
memory: 11064kb
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:
impossible
result:
ok single line: 'impossible'
Test #18:
score: 0
Accepted
time: 64ms
memory: 11196kb
input:
97913 60901 97087 58758 18416 94565 79381 52627 69968 79332 28132 89565 51130 90984 38208 62087 73972 29822 64941 67608 46225 644 81550 84132 50804 45068 71032 37455 7438 17667 9948 61523 4597 65924 91070 22443 25958 31160 14625 13587 2112 25093 77187 18779 6106 49481 75765 27 68731 49664 65562 5747...
output:
impossible
result:
ok single line: 'impossible'
Test #19:
score: 0
Accepted
time: 58ms
memory: 11452kb
input:
100000 4295 68473 92097 94209 57506 89966 61594 21263 43468 16856 26528 97633 11616 7895 91566 89927 92513 20274 32705 89318 9358 14599 89211 90918 37953 92203 53296 70865 58770 33236 52669 3248 81548 82487 62857 97586 633 88495 87068 7543 70408 70915 22405 88192 4700 57860 2102 58575 4690 48175 153...
output:
impossible
result:
ok single line: 'impossible'
Test #20:
score: 0
Accepted
time: 4ms
memory: 7824kb
input:
489 370 206 355 440 409 74 119 81 193 109 256 440 137 163 391 406 183 337 229 160 278 396 100 148 129 414 251 42 394 337 186 35 318 258 286 423 479 369 375 360 106 428 292 8 475 312 2 384 484 14 121 189 431 287 217 195 26 148 361 26 318 196 381 112 237 254 192 117 58 455 301 293 436 199 405 171 208 ...
output:
impossible
result:
ok single line: 'impossible'
Test #21:
score: 0
Accepted
time: 21ms
memory: 10904kb
input:
33015 15418 23360 4668 7924 16645 26717 17951 23465 11142 667 7557 10780 7606 30099 15114 6492 4564 28298 15451 2422 3409 26013 32382 16835 17083 30779 2940 26306 15689 21703 13789 23557 11954 7170 19696 29702 4215 24839 32580 30787 24785 22607 27747 13598 25853 29523 22282 599 22986 14068 4240 1064...
output:
impossible
result:
ok single line: 'impossible'
Test #22:
score: 0
Accepted
time: 66ms
memory: 11436kb
input:
98374 69 80221 33515 37515 86494 27854 81308 778 44462 43415 55710 50028 65094 73567 87006 88171 97819 24477 4645 23402 54901 76804 55599 36606 42426 25953 70106 36924 50723 75964 84800 97276 78457 67729 11888 51074 43110 2956 55007 15808 70905 47230 35496 83091 74080 17318 26289 80252 71084 67358 2...
output:
impossible
result:
ok single line: 'impossible'
Test #23:
score: 0
Accepted
time: 71ms
memory: 11568kb
input:
100000 84537 84238 74684 66651 3616 35955 74564 19702 17317 24588 56638 96514 28303 37186 19487 88194 65052 6877 82682 9889 50590 10934 38881 17555 63518 91566 29999 99309 73899 36549 95616 14122 57419 40633 58521 1396 9121 26409 71435 9509 46131 21457 78899 56135 79322 84823 7535 46220 71272 33613 ...
output:
impossible
result:
ok single line: 'impossible'
Test #24:
score: 0
Accepted
time: 64ms
memory: 12076kb
input:
97129 67880 23023 52047 91456 60613 60455 80799 63726 41173 92308 7359 20324 34227 53556 39628 79032 97091 29349 76596 43855 68113 91452 15530 95457 79529 95995 58417 38134 63320 62816 88030 64504 20613 94575 15002 91174 70672 72919 58718 83725 19912 66568 61433 46377 42668 1789 273 963 84824 19685 ...
output:
impossible
result:
ok single line: 'impossible'
Test #25:
score: 0
Accepted
time: 71ms
memory: 12132kb
input:
100000 62439 76409 95459 68478 20107 4685 27532 62113 92848 72835 54860 86728 66051 56643 2269 20555 7919 25817 53010 22929 55630 53209 94816 13964 28772 9971 64559 92028 42696 50041 46409 61841 15715 82777 45642 2509 99454 69078 6709 30403 73425 47062 34901 58963 72890 30783 5947 87873 85289 25969 ...
output:
impossible
result:
ok single line: 'impossible'
Test #26:
score: -40
Wrong Answer
time: 61ms
memory: 11356kb
input:
93749 44689 73457 25775 29184 44348 47456 33223 20237 10596 47456 39687 90032 9023 3104 75226 91414 49766 50441 8575 56785 35868 66876 50056 23168 8727 86092 8716 88971 27586 81685 67376 70224 32770 47040 80203 86109 614 84656 35993 22685 27225 43178 6667 74915 72029 65776 2893 43473 7746 70849 1715...
output:
46963
result:
wrong answer 1st lines differ - expected: '46976', found: '46963'
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%