QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346633 | #4889. 愚蠢的在线法官 | zzafanti | 3 | 240ms | 49292kb | C++20 | 1.2kb | 2024-03-08 19:49:00 | 2024-03-08 19:49:00 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
using E=long long;
constexpr E mod=998244353;
int n,k;
vector<int> vis,v,f,g;
vector<vector<int>> ver;
void dfs(int u,int fa=0){
if(vis[u]){
g[u]=1,f[u]=v[u];
}else{
f[u]=1,g[u]=0;
}
for(auto p:ver[u]){
if(fa==p) continue;
dfs(p,u);
E tmp=g[u];
g[u]=(g[u]*f[p]%mod+g[p]*f[u]%mod-2*g[u]*g[p]%mod)%mod;
g[u]=(g[u]+mod)%mod;
f[u]=((f[u]-v[u]*1ll*tmp%mod+mod)%mod*(f[p]-v[u]*1ll*g[p]%mod+mod)%mod+v[u]*1ll*g[u]%mod)%mod;
f[u]=(f[u]+mod)%mod;
//cerr<<u<<' '<<f[u]<<' '<<g[u]<<endl;
}
}
signed main(){
#ifdef zzafanti
freopen("in.in","r",stdin);
#endif // zzafanti
cin.tie(nullptr),cout.tie(nullptr)->sync_with_stdio(false);
cin>>n>>k;
v=f=g=vis=vector<int>(n+1);
ver.resize(n+1);
for(int i=1; i<=n; i++) cin>>v[i];
for(int i=1; i<=k; i++){
int a;
cin>>a;
vis[a]++;
}
for(int i=1; i<=n; i++){
if(vis[i]>1){
cout<<0;
return 0;
}
}
for(int i=1; i<n; i++){
int x,y;
cin>>x>>y;
ver[x].emplace_back(y);
ver[y].emplace_back(x);
}
dfs(1);
cout<<(f[1]+mod)%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 59ms
memory: 30720kb
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: 6
Accepted
time: 0ms
memory: 3676kb
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:
273617752
result:
ok 1 number(s): "273617752"
Test #3:
score: -6
Wrong Answer
time: 0ms
memory: 3648kb
input:
10 10 144077216 482507381 588297929 801675226 21569141 816295251 425507414 150613951 822735519 802838587 7 10 9 2 1 6 8 3 5 4 10 9 6 10 5 6 2 5 8 5 3 5 1 10 4 2 7 1
output:
307367792
result:
wrong answer 1st numbers differ - expected: '816324383', found: '307367792'
Subtask #3:
score: 0
Wrong Answer
Test #43:
score: 0
Wrong Answer
time: 195ms
memory: 49292kb
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:
212979457
result:
wrong answer 1st numbers differ - expected: '739558267', found: '212979457'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Wrong Answer
Test #77:
score: 0
Wrong Answer
time: 240ms
memory: 49260kb
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:
701772311
result:
wrong answer 1st numbers differ - expected: '771496320', found: '701772311'
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #3:
0%