QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733401 | #4889. 愚蠢的在线法官 | NineSuns | 3 | 554ms | 72528kb | C++14 | 2.5kb | 2024-11-10 18:38:35 | 2024-11-10 18:38:35 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define int long long
#define lowbit(x) ((x)&-(x))
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5e5+5, mod = 998244353;
int n, v[N], vis[N], dfn[N], sz[N], a[N], dt, ld[N], rd[N], k;
vector <int> e[N];
ll qpow (ll x, ll y = mod-2) {
ll res = 1;
while (y) {
if (y&1) res = res*x%mod;
x = x*x%mod; y >>= 1;
}
return res;
}
void dfs (int p, int fa) {
sz[p] = vis[p];
for (int i : e[p]) {
if (i == fa) continue;
dfs(i, p); sz[p] += sz[i];
}
sort(e[p].begin(), e[p].end(), [&](int x, int y) { return sz[x] < sz[y]; });
}
void tdfs (int p, int fa) {
ld[p] = dt+1;
if (vis[p]) dfn[p] = ++dt;
for (int i : e[p]) {
if (i == fa) continue;
tdfs(i, p);
}
rd[p] = dt;
}
ll ans = 1;
ll sk[N], f[N], g[N], tmp[N];
ll td[N];
void dfs2 (int p, int fa, int k) {
if (vis[p]) {
// cout << p << " " << v[p] << " " << k << endl;
g[dfn[p]] = (v[p]+k)%mod;
ans = ans*(v[p]+k)%mod;
sk[dfn[p]] = 1;
for (int j : e[p]) {
if (j == fa || !sz[j]) continue;
dfs2(j, p, -v[p]);
}
for (int j = ld[p]+1;j <= rd[p];j++) sk[j] = 0;
return;
}
ll s = 0;
for (int i : e[p]) {
if (i == fa || !sz[i]) continue;
dfs2(i, p, k);
tmp[i] = (1-s)%mod;
td[i] = (v[p]+k)%mod;
ll tk = k;
for (int j = ld[i];j <= rd[i];j++) {
ll sv = qpow(g[j])*td[i]%mod;
(k -= (v[p]+tk)%mod*sv%mod*sk[j]%mod) %= mod; (s += sv*sk[j]%mod*tmp[i]) %= mod;
}
}
ll st = 0;
for (int I = 1l*e[p].size()-1; ~I; I--) {
int i = e[p][I];
if (i == fa || !sz[i]) continue;
ll ts = 0;
for (int j = ld[i];j <= rd[i];j++) (ts += qpow(g[j])*sk[j]) %= mod;
for (int j = ld[i];j <= rd[i];j++) (sk[j] = (1-tmp[i]-st*td[i])%mod*sk[j]) %= mod;
(st += ts*(1-tmp[i]-st*td[i]%mod)%mod) %= mod;
}
}
void solve () {
cin >> n >> k;
for (int i = 1;i <= n;i++) cin >> v[i];
for (int i = 1;i <= k;i++) {
cin >> a[i];
if (vis[a[i]]) {
cout << "0"; return;
}
vis[a[i]] = 1;
}
for (int i = 1;i < n;i++) {
int x, y; cin >> x >> y;
e[x].pb(y); e[y].pb(x);
}
dfs(1, 0); tdfs(1, 0);
dfs2(1, 0, 0);
if (ans < 0) ans += mod;
cout << ans;
}
signed main () {
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int T = 1;
while (T--) solve();
return 0;
}
详细
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 194ms
memory: 29860kb
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: 34412kb
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
Accepted
time: 0ms
memory: 30384kb
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:
816324383
result:
ok 1 number(s): "816324383"
Test #4:
score: 6
Accepted
time: 0ms
memory: 34404kb
input:
10 2 136932305 774891472 782708047 361400653 241613404 206577781 241535900 917672952 105332067 165467540 2 5 2 4 5 4 1 4 7 2 3 5 10 5 8 3 6 10 9 10
output:
830180673
result:
ok 1 number(s): "830180673"
Test #5:
score: 6
Accepted
time: 0ms
memory: 32292kb
input:
10 3 106669121 934163752 505411505 487296100 135689018 776930268 130240777 167200291 726820445 449323201 10 5 2 9 5 3 5 2 9 1 3 7 1 8 7 6 2 4 9 10 6
output:
516982188
result:
ok 1 number(s): "516982188"
Test #6:
score: 6
Accepted
time: 2ms
memory: 34272kb
input:
10 4 554115046 86946870 492346089 759285688 597393634 534292327 742418751 40866289 456853511 777192624 6 10 1 4 3 4 5 4 7 4 2 7 9 4 10 2 8 7 1 7 6 10
output:
525980396
result:
ok 1 number(s): "525980396"
Test #7:
score: 6
Accepted
time: 0ms
memory: 34424kb
input:
10 5 156072097 743398614 639218862 297252114 250194624 291963313 870909501 644015194 402352389 623034872 7 2 6 5 8 3 7 10 7 5 7 4 3 6 4 9 4 1 10 2 6 8 10
output:
971134438
result:
ok 1 number(s): "971134438"
Test #8:
score: 6
Accepted
time: 0ms
memory: 34396kb
input:
10 6 58754522 928459597 174632208 377936445 469281312 236879760 214372862 700076292 513613148 778426835 2 9 6 8 7 10 1 3 9 3 10 9 7 9 8 7 5 7 4 9 6 4 2 10
output:
383720205
result:
ok 1 number(s): "383720205"
Test #9:
score: 6
Accepted
time: 5ms
memory: 34296kb
input:
10 7 168762354 271736588 761917216 86643499 677986829 885713846 696532784 435399905 113862203 798130316 10 6 8 5 2 1 4 6 1 7 1 3 7 8 6 9 3 5 9 2 9 10 8 4 5
output:
336844044
result:
ok 1 number(s): "336844044"
Test #10:
score: 6
Accepted
time: 4ms
memory: 32364kb
input:
10 8 727643452 96661577 109323043 94391368 943841820 772388814 620778403 424167899 950821917 236642846 6 2 8 1 7 3 10 4 4 6 1 4 10 6 3 4 7 3 2 6 9 10 5 1 8 2
output:
180649465
result:
ok 1 number(s): "180649465"
Test #11:
score: 6
Accepted
time: 0ms
memory: 30300kb
input:
10 9 117163394 156945447 136708770 224773742 105988662 323714230 608540583 786406145 376690056 848998167 5 3 1 8 9 4 2 10 7 2 5 3 5 10 2 7 2 4 3 6 3 1 4 9 5 8 7
output:
199480877
result:
ok 1 number(s): "199480877"
Test #12:
score: 6
Accepted
time: 2ms
memory: 34344kb
input:
10 1 310390327 26621492 98419973 106234069 846950161 118046850 174859624 961989377 51668388 989751256 10 7 1 9 1 2 7 5 7 10 9 6 9 8 2 4 2 3 5
output:
989751256
result:
ok 1 number(s): "989751256"
Test #13:
score: 6
Accepted
time: 0ms
memory: 30272kb
input:
10 10 455951699 832766533 368655882 274544983 630176565 149197662 125666866 811780187 718334218 758563081 6 4 8 5 7 1 2 10 9 3 7 1 10 1 4 7 9 7 6 10 8 10 5 4 2 4 3 9
output:
859352350
result:
ok 1 number(s): "859352350"
Test #14:
score: 6
Accepted
time: 0ms
memory: 34408kb
input:
10 2 987594303 113921174 60526162 363948313 953235693 442146116 239088362 970808700 672708631 266329194 1 7 3 1 5 1 7 3 4 3 9 5 6 5 10 7 2 7 8 4
output:
670634365
result:
ok 1 number(s): "670634365"
Test #15:
score: 6
Accepted
time: 3ms
memory: 34340kb
input:
10 3 816651453 62348752 681535935 116805607 955973251 476700964 874368097 579852140 368797919 88107985 3 8 9 2 1 4 1 10 2 3 2 7 4 5 4 9 10 8 10 6 3
output:
384680534
result:
ok 1 number(s): "384680534"
Test #16:
score: 0
Wrong Answer
time: 2ms
memory: 34296kb
input:
10 4 58528783 12671113 11126837 192243188 969173998 711355158 552139230 134986041 320297780 856214300 4 10 2 5 6 1 9 1 2 6 4 6 5 9 8 9 3 2 10 2 7 4
output:
15648591
result:
wrong answer 1st numbers differ - expected: '935582164', found: '15648591'
Subtask #3:
score: 0
Wrong Answer
Test #43:
score: 0
Wrong Answer
time: 422ms
memory: 68440kb
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:
326855881
result:
wrong answer 1st numbers differ - expected: '739558267', found: '326855881'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #77:
score: 16
Accepted
time: 554ms
memory: 71828kb
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: 16
Accepted
time: 541ms
memory: 72528kb
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: 16
Accepted
time: 522ms
memory: 72352kb
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
Time Limit Exceeded
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:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #3:
0%