QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296900#4889. 愚蠢的在线法官MEKHANE19 202ms76140kbC++17805b2024-01-03 19:24:332024-01-03 19:24:33

Judging History

你现在查看的是最新测评结果

  • [2024-01-03 19:24:33]
  • 评测
  • 测评结果:19
  • 用时:202ms
  • 内存:76140kb
  • [2024-01-03 19:24:33]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int N=5e5+5,mod=998244353;
int n,k,val[N],vis[N],f[N],g[N];
vector<int> v[N];
void dfs(int x,int fa){
    int c0=1,c1=0;
    for(auto dq:v[x]) if(dq!=fa){dfs(dq,x); int d0=(c0*f[dq]+c0*g[dq]%mod*(mod-val[x]))%mod,d1=(c1*f[dq]+(c0+c1*val[x])%mod*g[dq]%mod*(mod-1))%mod; c0=d0,c1=d1;}
    if(vis[x]) f[x]=c0*val[x]%mod,g[x]=c0; 
    else f[x]=(c0-val[x]*c1%mod+mod),g[x]=mod-c1;
}
signed main(){
    ios::sync_with_stdio(false);
    cin>>n>>k;
    rep(i,1,n) cin>>val[i];
    rep(i,1,k){
        int x; cin>>x;
        if(vis[x]){cout<<0; return 0;} vis[x]=1;
    }
    rep(i,1,n-1){int u,vv; cin>>u>>vv,v[u].push_back(vv),v[vv].push_back(u);}
    dfs(1,0),cout<<f[1];
}

詳細信息

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 59ms
memory: 23332kb

input:

499999 500000
879485015 176694934 629415436 677018935 33186863 696674214 19586946 878479076 318116264 823399347 140314195 715329843 996129441 446979068 600062488 847953138 978347569 865596472 147980317 199880680 187953368 989585254 457868128 466175307 381871948 369138343 826894839 963935318 36550896...

output:

0

result:

ok 1 number(s): "0"

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 19340kb

input:

10 1
663730929 273617752 74933376 562874267 346105266 779139305 198742356 291012786 227170675 127136999
2
10 8
5 10
1 5
9 8
6 10
4 6
3 1
2 4
7 3

output:

1271862105

result:

wrong answer 1st numbers differ - expected: '273617752', found: '1271862105'

Subtask #3:

score: 0
Wrong Answer

Test #43:

score: 11
Accepted
time: 162ms
memory: 47568kb

input:

500000 600
375999961 486674339 753591626 263678997 153496902 843204506 294273913 59353025 80121537 938426018 309354784 359915003 480316315 880954496 544396164 478808641 583197144 202111021 277512785 193266475 511298159 750302398 30978705 278891583 701736665 516664158 47658598 456194527 517690925 870...

output:

739558267

result:

ok 1 number(s): "739558267"

Test #44:

score: -11
Wrong Answer
time: 166ms
memory: 47652kb

input:

500000 600
144424234 822427316 300192847 7262228 210896294 454472658 15628508 599308527 39208834 748087468 100403532 861554271 440434658 207763150 960826231 405540153 513306322 903562629 19659973 24682032 339889038 859238787 933505007 113096874 144805990 391745221 750054096 992392845 976030209 54069...

output:

1142304103

result:

wrong answer 1st numbers differ - expected: '144059750', found: '1142304103'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 16
Accepted

Test #77:

score: 16
Accepted
time: 202ms
memory: 49516kb

input:

500000 500000
200910665 704700912 664276 824905098 512233060 623259142 478040808 509760810 756074623 387351466 261683363 140331101 135736712 184881987 425557684 61914673 951508934 787260914 386285199 40458274 175322609 429002885 606957721 742057849 342942076 104844271 656874266 826513447 76400873 55...

output:

771496320

result:

ok 1 number(s): "771496320"

Test #78:

score: 0
Accepted
time: 190ms
memory: 49572kb

input:

500000 500000
393325784 423307620 769839934 488701594 34980277 797798611 971252417 460892286 567253464 767364025 93413829 75786578 256363071 217722512 645295877 510711584 480877049 428293642 214340569 818013745 26677511 669553845 89063601 534123295 248791524 138950624 251295359 636455647 417371091 7...

output:

439789184

result:

ok 1 number(s): "439789184"

Test #79:

score: 0
Accepted
time: 175ms
memory: 50496kb

input:

500000 500000
304834659 23334136 281137008 195895112 196794218 9096321 550195738 251406926 794310053 392944702 896889429 377202988 383812779 855411433 996638204 176946965 14610588 31326580 287865536 285356776 15181214 721975103 7479393 923265076 700703478 244253830 13595300 191060192 506315015 82731...

output:

386763205

result:

ok 1 number(s): "386763205"

Test #80:

score: 0
Accepted
time: 195ms
memory: 76140kb

input:

500000 500000
963769621 792032953 548743692 812303224 806859822 107106153 670071669 457532666 516564922 867509289 563112863 620766458 971804950 533739313 126272905 817695615 569475276 227580608 323342974 375310982 265196242 579298928 82855065 820284887 873105018 906167288 489289717 472219706 8127735...

output:

490477004

result:

ok 1 number(s): "490477004"

Test #81:

score: 0
Accepted
time: 160ms
memory: 49988kb

input:

500000 500000
934825416 221317375 979103615 273478171 355638257 208592783 254723141 463073783 405970022 680755268 266037075 931070258 928975898 442231376 471302244 364395206 266480387 284288074 707928785 957518641 526274338 899411209 442421594 13370142 383410592 249354068 255747031 99288455 18754772...

output:

809226100

result:

ok 1 number(s): "809226100"

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #3:

0%