QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#462488 | #8533. Island Vacation | zlxFTH | 100 ✓ | 687ms | 8324kb | C++14 | 4.3kb | 2024-07-03 20:16:02 | 2024-07-03 20:16:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e4 + 5;
const int P = 1e9 + 7;
inline LL qp(LL a, LL b = P - 2) {
LL c = 1;
while (b) {
if (b & 1) (c *= a) %= P;
(a *= a) %= P;
b /= 2;
}
return c;
}
LL inv[N], fac[N], ifac[N];
void init() {
fac[0] = 1;
for (int i = 1; i < N; ++i) {
inv[i] = qp(i);
fac[i] = fac[i - 1] * i % P;
}
ifac[N - 1] = qp(fac[N - 1]);
for (int i = N - 1; i > 0; --i) {
ifac[i - 1] = ifac[i] * i % P;
}
}
int n, m, cnt;
LL p[N], q[N];
vector<int> G[N], E[N];
int ti, low[N], dfn[N];
vector<int> stk;
void tarjan(int u, int fa) {
low[u] = dfn[u] = ++ti;
stk.push_back(u);
for (auto v : G[u]) if (v != fa) {
if (!dfn[v]) {
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (dfn[u] <= low[v]) {
if (dfn[v] == low[v]) {
E[u].emplace_back(v);
stk.pop_back();
} else {
int o = ++cnt;
while (stk.back() != v) {
E[o].emplace_back(stk.back());
stk.pop_back();
}
E[o].emplace_back(stk.back());
stk.pop_back();
E[u].emplace_back(o);
}
}
} else {
low[u] = min(low[u], dfn[v]);
}
}
}
LL f[N], g[N], vis[N];
vector<LL> h[N], pw[N];
void dp1(int u) {
if (u > n) {
LL r = 1;
for (auto v : E[u]) {
dp1(v);
LL rs = 0;
for (int i = 0; i < h[v].size(); ++i) if (h[v][i]) {
(rs += pw[v][i + 1] * fac[i] % P * h[v][i] % P
* inv[G[v].size() - 1 - 2 * i] % P) %= P;
}
(r *= rs) %= P;
}
(f[u] += r * 2) %= P;
} else {
int cir = 0;
for (auto v : E[u]) cir += v > n;
pw[u].resize(cir + 2);
pw[u][0] = 1;
for (int i = 1; i <= cir + 1; ++i) {
pw[u][i] = pw[u][i - 1] * q[u] % P;
}
h[u].resize(cir + 1);
h[u][0] = 1;
for (auto v : E[u]) {
dp1(v);
if (v <= n) continue;
for (int i = cir; i >= 0; --i) if (h[u][i]) {
(h[u][i + 1] += h[u][i] * f[v] % P
* inv[G[u].size() - (u != 1) - 2 * i] % P) %= P;
}
}
}
}
void dp2(int u) {
if (u <= n) {
for (int i = 0; i < h[u].size(); ++i) if (h[u][i]) {
(g[u] += vis[u] * pw[u][i] % P * fac[i] % P * h[u][i] % P
* (2 * i == G[u].size() - (u != 1) ? 1 : p[u]) % P) %= P;
}
for (auto v : E[u]) {
if (v > n) {
for (int i = 0; i + 1 < h[u].size(); ++i) {
(h[u][i + 1] += P - h[u][i] * f[v] % P
* inv[G[u].size() - (u != 1) - 2 * i] % P) %= P;
}
}
LL &r = vis[v];
for (int i = 0; i < h[u].size(); ++i) if (h[u][i]) {
(r += vis[u] * pw[u][i + 1] % P * fac[i] % P * h[u][i] % P
* inv[G[u].size() - (u != 1) - 2 * i] % P) %= P;
}
dp2(v);
if (v > n) {
for (int i = int(h[u].size()) - 1; i >= 0; --i) if (h[u][i]) {
(h[u][i + 1] += h[u][i] * f[v] % P
* inv[G[u].size() - (u != 1) - 2 * i] % P) %= P;
}
}
}
} else {
auto work = [&]() {
LL r = vis[u];
for (auto v : E[u]) {
(vis[v] += r) %= P;
LL rs = 0;
for (int i = 0; i < h[v].size(); ++i) if (h[v][i]) {
(rs += pw[v][i + 1] * fac[i] % P * h[v][i] % P
* inv[G[v].size() - 1 - 2 * i] % P) %= P;
}
(r *= rs) %= P;
}
};
work();
reverse(E[u].begin(), E[u].end());
work();
for (auto v : E[u]) dp2(v);
}
}
void solve() {
cin >> n >> m;
cnt = n;
for (int i = 1; i <= n; ++i) {
cin >> p[i];
q[i] = (1 + P - p[i]) % P;
}
for (int i = 1; i <= n; ++i)
G[i].clear();
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
G[u].emplace_back(v);
G[v].emplace_back(u);
}
{
ti = 0;
stk.clear();
for (int i = 1; i <= 2 * n; ++i) {
low[i] = dfn[i] = 0;
f[i] = g[i] = vis[i] = 0;
h[i].clear();
pw[i].clear();
E[i].clear();
}
}
tarjan(1, 0);
dp1(1);
vis[1] = 1;
dp2(1);
for (int i = 1; i <= n; ++i)
cout << g[i] << " \n"[i == n];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
init();
int t;
cin >> t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 4.34783
Accepted
time: 5ms
memory: 5956kb
input:
2 3 2 0 10 111111112 1 3 2 3 6 5 500000004 0 0 0 0 0 1 5 1 3 4 5 5 6 1 2
output:
0 888888896 111111112 500000004 166666668 166666668 83333334 0 83333334
result:
ok 2 lines
Test #2:
score: 4.34783
Accepted
time: 4ms
memory: 5920kb
input:
2 5 5 333333336 333333336 0 0 0 1 2 2 3 3 4 4 5 1 5 5 5 0 0 0 0 0 1 2 2 3 2 4 1 4 1 5
output:
777777784 222222224 0 0 0 0 0 333333336 0 666666672
result:
ok 2 lines
Test #3:
score: 4.34783
Accepted
time: 0ms
memory: 5996kb
input:
1 11 13 2 3 4 5 6 7 8 9 10 11 12 1 2 1 3 2 3 2 4 4 5 2 5 4 8 5 9 2 6 6 7 2 7 6 10 5 11
output:
133332478 200000394 577778352 999999971 399999938 933333282 355555536 800000020 18 600000029 18
result:
ok single line: '133332478 200000394 577778352 ...55536 800000020 18 600000029 18'
Test #4:
score: 4.34783
Accepted
time: 2ms
memory: 6052kb
input:
10 9 10 156241079 379541254 371589355 610239128 49714057 421621164 578509177 629476125 959162361 1 4 8 9 3 4 2 8 1 6 2 5 4 8 4 7 7 8 5 9 10 11 374116260 83263449 755436519 419356370 199185436 630946701 202626825 769874541 945053459 202188252 2 8 4 6 1 4 8 9 2 9 1 9 7 10 2 5 7 9 3 5 6 9 11 11 5912...
output:
156241079 581022743 917237336 654090753 283516650 921879468 36045205 510422725 939544077 14791903 324370756 795356662 831332131 534525350 270628991 8908779 48718773 415755370 755611314 751902387 768822757 959033672 355792462 245288036 935578463 489434854 652999373 507116973 37886731 296144335 816838...
result:
ok 10 lines
Test #5:
score: 4.34783
Accepted
time: 4ms
memory: 6048kb
input:
10 9 11 211755593 863978352 292138943 850121258 174200766 76231890 125090458 818563596 501765461 8 9 5 7 1 9 6 7 3 7 2 8 2 5 1 8 7 8 4 7 4 6 10 12 271033216 545744125 536383199 238394424 897610574 935057864 648703551 389007542 351081312 607139124 1 3 5 7 4 8 3 5 6 7 3 8 2 6 5 6 5 8 6 9 3 10 2 9 1...
output:
308621652 883968415 982169568 480461004 299439877 167332397 856003736 570294439 451708948 271033216 854149255 837985588 823436460 599878312 464230393 751236846 123410292 744105781 530533900 578164881 767285306 379875233 915480421 650692454 294277865 348663529 201562287 919604012 593874866 350519189 ...
result:
ok 10 lines
Test #6:
score: 4.34783
Accepted
time: 9ms
memory: 7356kb
input:
3 94 93 716690368 156752297 913895827 268482677 882522602 547160853 389245810 375523323 895105390 254424101 538701151 198984912 807025679 346803749 571407109 783756836 693285484 906928732 926915106 761785975 613428534 858135966 714778886 215343323 22512420 614632073 510503478 32904507 140760828 125...
output:
716690368 491679565 637840709 538350901 690574815 269938364 243685817 458958906 815665672 519562661 615911790 141654820 493889248 608407455 847798640 701288661 364776560 85334189 463787785 471574345 208681594 159291344 589989537 239461173 895901419 368710406 733002790 531604221 80318687 672241116 33...
result:
ok 3 lines
Test #7:
score: 4.34783
Accepted
time: 3ms
memory: 8324kb
input:
1 10000 9999 576833221 741254435 117793269 701925229 22005656 239319661 86240344 105803398 467040969 756270105 116085215 861940373 149801070 899613063 392056836 99256548 852081659 560316430 196449470 531625852 642203107 358691908 324421505 235340103 951148812 605308763 135005889 485412373 381878573...
output:
576833221 704835499 908335047 55512117 141643172 511388 685927479 656482926 136091930 702025696 812206778 596850592 355757127 24257657 277465547 830233158 611587321 301146489 840322512 18820205 798926467 578897563 356138711 681255183 761206632 358195149 912681865 897565004 804247230 949827105 654674...
result:
ok single line: '576833221 704835499 908335047 ...60 333679124 44781812 862486337'
Test #8:
score: 4.34783
Accepted
time: 7ms
memory: 8084kb
input:
1 10000 10943 32326933 812025401 210221546 72620980 657376233 724392018 207844388 190240185 256584719 981809953 974774894 381130090 244450463 990354318 76848594 851516602 806739060 159702372 658590506 478233241 418138741 748284798 980526211 421898568 493428394 506703542 546699994 372003968 51934363...
output:
32326933 256446248 556675125 788928813 149447028 943113413 620024709 183686776 294955364 112108972 723688042 221805637 413517568 64185528 484253260 473773654 920395006 385322044 842753538 526653959 80478409 812047606 565318695 786591032 562599457 369642852 968235786 541036782 719948966 173116630 852...
result:
ok single line: '32326933 256446248 556675125 7...21 476159625 214744068 75547224'
Test #9:
score: 4.34783
Accepted
time: 11ms
memory: 7324kb
input:
3 1897 2095 474609288 779474631 779968093 949761404 645301315 770889157 472994134 972074110 289308071 761535595 905289229 732065100 461703861 775513058 340348205 888480327 12015066 695547901 530980608 622881300 397044812 278294723 969766632 547059540 97912827 508554679 677806412 697750963 740912427...
output:
474609288 231598073 902601855 112471498 339547454 688867415 421431814 742177889 945075063 405075705 706552396 732235506 414447531 301182980 312107337 62885880 256074114 443124719 490827230 76158595 346230129 532979522 910928845 778311727 835414044 806311075 47693554 604699625 557533901 828210816 598...
result:
ok 3 lines
Test #10:
score: 4.34783
Accepted
time: 8ms
memory: 7936kb
input:
1 10000 13332 23272604 106456403 552404970 340873196 441725266 584537931 651297537 554527114 999835377 291169171 881406071 293435749 796999561 286225242 138053764 84588107 774407928 243711779 963791106 183787711 671593095 70037130 624801729 751631248 434538704 188398359 443667223 966614161 85295170...
output:
564287678 100157383 927077052 56549605 981100457 843781520 698566296 467145990 708104787 582246612 984313762 52643317 805279350 348879775 521951793 125281563 797945933 151507391 857637990 292671996 747319111 607005946 476322841 589130386 342099434 243209342 260444464 921087733 504429045 89223763 299...
result:
ok single line: '564287678 100157383 927077052 ...0 718913611 479701993 622175303'
Test #11:
score: 4.34783
Accepted
time: 11ms
memory: 7628kb
input:
3 1463 1949 804075450 849001569 780226578 84218572 585348631 201620704 903592060 23034348 422772787 993091934 962575074 61498354 989261183 926127854 440326688 25255594 880702106 703894076 759539186 219684073 448090899 848745334 41033887 23369774 848538087 525349972 700977795 312630799 995834542 498...
output:
292521922 287624275 52496488 778866419 97573245 527601913 990242946 529894483 472373168 349032035 492532499 650058057 41168188 902576127 844636275 770653245 422016414 424156255 677069591 268144613 373420067 849387243 144042645 61267179 656937281 731569093 713034482 273998296 879458379 279549595 2862...
result:
ok 3 lines
Test #12:
score: 4.34783
Accepted
time: 10ms
memory: 7984kb
input:
1 10000 10314 399981704 350800784 166636544 179853806 33042404 86064863 213399756 312153691 697964372 305222600 196959690 226031215 963691253 793135536 591358392 191194147 608131246 729569240 6701657 136288535 904248767 745750756 19509028 505742117 798834348 243275344 694690379 912671715 519316986 ...
output:
399981704 575311029 575311029 575311029 654136073 414939845 353310300 93122062 249832602 575311029 248848299 349504616 831277883 20189763 837334533 679374563 282763384 663385833 157686294 660311992 533455980 788435738 91986557 62916756 208416682 145672243 984588912 820354042 512723855 855352179 1453...
result:
ok single line: '399981704 575311029 575311029 ...9 563109132 791004144 575311029'
Test #13:
score: 4.34783
Accepted
time: 8ms
memory: 7944kb
input:
1 10000 14544 74244896 339306242 50020755 817510228 460696636 469808051 155933575 635899119 633244980 365257928 938421332 496186863 652825873 852388335 726192462 669683699 599562596 893542248 778944170 486074660 787965049 635147678 895809246 752247698 791419586 34270072 616383249 497619068 11727106...
output:
23960599 297951121 780178446 383765950 441725587 52887322 48645026 969943937 473275423 617291084 681433934 183591591 505238681 114591034 205858082 86942185 299053630 772710758 510074837 113236844 436113047 79313214 142014576 674711093 280818954 319550860 666792919 328466024 458895778 398485271 91736...
result:
ok single line: '23960599 297951121 780178446 3...8 925853814 590670834 434675708'
Test #14:
score: 4.34783
Accepted
time: 12ms
memory: 7728kb
input:
3 364 400 184831392 322857279 815903253 677965630 300678967 534281908 628461087 590429679 889408867 408654891 346772772 481156318 158940706 878527590 480738355 13123287 910680778 416919745 131908371 188483119 223576496 422098383 787040434 0 0 779889009 993807563 973938011 834203840 1 315303008 5082...
output:
184831392 831845198 0 0 453162929 0 903397983 0 879460565 0 0 813927981 386398135 462276461 301870067 831845198 787386062 113213468 0 779040407 512635534 0 445414698 0 836018542 0 737352902 18786971 367499726 82335145 283772547 484557514 0 294807077 573066928 831845198 0 312078165 18923700 393044795...
result:
ok 3 lines
Test #15:
score: 4.34783
Accepted
time: 10ms
memory: 7344kb
input:
3 1466 1531 922720536 629005703 983240032 350947246 256000722 698679004 211654861 114036597 144399752 167026536 463996486 959705855 444763005 762417508 902715477 673468121 814048083 831832585 852519594 962453264 698959544 549808404 25414406 596842459 774662962 151620087 315149306 150690213 48227968...
output:
922720536 76693275 580755740 957204211 618232020 559967370 624129265 663663458 234990771 840676760 435929175 590091096 743801440 167684706 234990771 340277269 803285662 549241158 255289867 975653120 78661795 984339178 731430658 663860770 201769717 565327554 495813741 87148560 338015060 536870045 234...
result:
ok 3 lines
Test #16:
score: 4.34783
Accepted
time: 13ms
memory: 7940kb
input:
1 10000 11944 166332897 341402193 451476981 645601935 482996064 569288854 341776560 764393689 123072751 697995816 818881168 844852925 757125373 534760733 132649601 173135023 436697832 920849536 560157881 51022469 790686244 514595504 23439740 899847037 39148078 952261186 535804075 732068812 30737645...
output:
518251351 678274953 970813527 700950906 223162059 786615562 17960634 756965481 788345801 183549881 613930015 520491623 659915130 710775356 243290148 834471768 254224407 356258804 96192477 140674327 994229901 14927069 718185910 768185992 674210547 314888709 671984386 498271582 317874826 42241395 7175...
result:
ok single line: '518251351 678274953 970813527 ...3 612056134 770270216 956649422'
Test #17:
score: 4.34783
Accepted
time: 17ms
memory: 7884kb
input:
1 10000 14949 445807845 41486003 292461319 274447930 43586742 144184961 955726447 947906702 93907878 581784067 994565884 161051925 732155319 791242435 846379763 387787485 541540074 133657525 685358635 545069356 512884308 905261280 279831247 311038063 96641269 887491773 532513403 320280052 370115839...
output:
307758799 711996143 83736321 93109010 264961972 706121339 242995265 466128841 36847162 455403779 365588186 983287941 162066468 235212759 916309308 847267374 984982252 613993192 725271339 960293352 779957730 383737646 658570102 462796167 694852700 209533851 322621067 217581491 904833750 287694603 754...
result:
ok single line: '307758799 711996143 83736321 9...74 165622203 29092311 159573902'
Test #18:
score: 4.34783
Accepted
time: 9ms
memory: 7616kb
input:
3 7486 9123 679044939 745060822 0 313853244 876616276 936686875 1 0 8976877 832106117 0 894950509 170920333 774065740 5745899 1 40140693 819071291 739212251 264988399 230242604 527185147 1 964361570 5881486 0 655753319 97038172 426215540 17105579 787299330 149316908 650945053 690554987 1 0 55328239...
output:
679044939 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 890862478 0 0 0 0 0 0 0 0 0 0 0 924155622 0 0 0 0 0 0 0 0 0 0 0 545431088 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 832370196 0 416924174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 3 lines
Test #19:
score: 4.34783
Accepted
time: 13ms
memory: 7864kb
input:
3 9370 11268 711164105 899197102 908629715 992902809 943431188 609929773 77613267 572629631 788655576 798308211 783848959 694196642 62749095 605955347 307236329 184523040 364909367 975570957 151013015 519964435 179076548 407077650 769844263 589544128 216032694 601855730 784780715 191280132 67033245...
output:
796176822 372699777 445854857 334600837 682263249 98788422 835565363 21522420 883054442 804679336 437181839 32800186 323113584 626901342 592779315 582574043 961239388 42245383 184207964 244745735 721296038 810483301 532367561 556151300 984321631 422967810 566469716 1319370 711536784 770137736 771164...
result:
ok 3 lines
Test #20:
score: 4.34783
Accepted
time: 203ms
memory: 7992kb
input:
1 10000 12847 585012089 726215459 776197761 922407522 398972335 484628127 295766050 141203789 116692194 502371103 168110238 386261109 35623016 13366467 183431163 330814985 953858754 458313028 600518660 874199097 265910691 227369704 605751023 350837817 284169231 756465321 30989650 73813278 36419077 ...
output:
341282022 314626915 521984319 959163283 426867421 538029998 733847620 401552639 332193084 931153790 661418309 942219238 861583318 795960435 688003456 567612259 376846914 233587 535749019 364278131 316356300 333682393 246138468 776360035 364482271 122116761 931153790 658297928 939223110 96427273 6465...
result:
ok single line: '341282022 314626915 521984319 ...1 228250845 461900729 935671551'
Test #21:
score: 4.34783
Accepted
time: 687ms
memory: 7976kb
input:
1 9999 14997 371850406 180293163 766550290 103212526 214392166 480536182 886359647 722393262 516379312 491364272 992896955 234121831 225964011 333870959 53013555 300758030 550735207 761508243 142390810 211672008 520918181 322706826 270746552 581930565 235876328 138636406 250966133 171731449 7853759...
output:
173566428 615858562 432054495 761922604 219163458 902513888 647811619 987224684 741003384 617929826 298152129 47965561 807680265 845988075 488060626 318277858 758744881 568018362 860467992 781549082 69975678 462331715 334523664 220501037 429544518 57516801 413788269 671174090 865278096 585979710 360...
result:
ok single line: '173566428 615858562 432054495 ...61 310868347 595509989 97384949'
Test #22:
score: 4.34783
Accepted
time: 383ms
memory: 7496kb
input:
3 2410 3031 1 588007765 481177480 105433833 338665365 0 498728825 725924281 37780399 545378609 722178352 241964165 592727002 603929094 290265987 380121207 275039311 280349076 908897674 447313439 417618597 169373313 1 291590307 396387463 1 523153881 363071402 87700312 677133009 184538157 483311743 6...
output:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 3 lines
Test #23:
score: 4.34783
Accepted
time: 293ms
memory: 7484kb
input:
3 1915 2257 395987795 839404392 822192278 160521894 178536377 650067511 4008417 449173588 64992895 839129530 467233849 544539113 992200696 776511262 703389882 94540936 223154898 426250698 745794557 796582959 315916002 112141394 227297480 520374973 347500285 184823868 750987257 627912504 779610299 7...
output:
977584660 963680275 505670196 30395478 641495556 513760511 99158987 363282478 115860864 903115556 676868029 165194530 286732874 930083404 265931261 724845165 326579001 643962897 133706112 382116032 999001398 303699624 112820821 183493136 914151955 527763648 513760511 380804869 179286305 366886128 71...
result:
ok 3 lines