QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#800392 | #8531. A Graph Problem | zhenghanyun# | 100 ✓ | 162ms | 25244kb | C++14 | 1.9kb | 2024-12-06 09:54:49 | 2024-12-06 09:54:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int M = 4e5 + 5;
const int base = 10;
const int mod = 1e9 + 7;
int n, m, fa[N], u[M], v[M];
vector <int> vec[N];
ll ans[N], tag1[N], tag2[N];
inline int _find(int u) {
return (fa[u] == u) ? u : (fa[u] = _find(fa[u]));
}
inline ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) {
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
inline ll inv(ll a) {
return qpow(a, mod - 2);
}
inline void merge(int u, int v, int w) {
int fu = _find(u), fv = _find(v);
if (fu == fv) {
return;
}
if (vec[fu].size() > vec[fv].size()) {
swap(u, v);
swap(fu, fv);
}
ll p = (ans[u] * tag1[fu] + tag2[fu]) % mod, q = (ans[v] * tag1[fv] + tag2[fv]) % mod;
for (auto u: vec[fu]) {
ans[u] = (ans[u] * tag1[fu] + tag2[fu]) % mod;
ans[u] = (ans[u] * base + w) % mod;
ans[u] = (ans[u] * qpow(base, vec[fv].size() - 1) + q) % mod;
}
tag1[fv] = tag1[fv] * base % mod;
tag2[fv] = (tag2[fv] * base + w) % mod;
ll t = qpow(base, vec[fu].size() - 1);
tag1[fv] = tag1[fv] * t % mod;
tag2[fv] = (tag2[fv] * t + p) % mod;
fa[fu] = fv;
for (auto u: vec[fu]) {
vec[fv].emplace_back(u);
ans[u] = (ans[u] - tag2[fv] + mod) * inv(tag1[fv]) % mod;
}
}
int main() {
#ifdef LOCAL
assert(freopen("test.in", "r", stdin));
assert(freopen("test.out", "w", stdout));
#endif
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
fa[i] = i;
vec[i].emplace_back(i);
tag1[i] = 1, tag2[i] = 0;
}
for (int i = 1; i <= m; ++i) {
cin >> u[i] >> v[i];
}
for (int i = 1; i <= m; ++i) {
merge(u[i], v[i], i);
}
for (int i = 1; i <= n; ++i) {
cout << (ans[i] * tag1[_find(i)] + tag2[_find(i)]) % mod << "\n";
}
return 0;
}
详细
Pretests
Final Tests
Test #1:
score: 4.34783
Accepted
time: 3ms
memory: 13980kb
input:
3 2 1 2 2 3
output:
12 12 21
result:
ok 3 lines
Test #2:
score: 4.34783
Accepted
time: 0ms
memory: 13932kb
input:
5 6 1 2 3 4 2 4 2 3 2 5 1 5
output:
1325 1325 2315 2315 5132
result:
ok 5 lines
Test #3:
score: 4.34783
Accepted
time: 3ms
memory: 15960kb
input:
15 14 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15
output:
678925929 678925929 678862929 678787329 678709839 678632097 178554320 218476543 321398766 431520989 542453212 653475435 764507558 875540761 986574081
result:
ok 15 lines
Test #4:
score: 4.34783
Accepted
time: 3ms
memory: 14032kb
input:
1850 2000 535 1272 1182 1267 73 290 1339 1470 894 1137 784 1364 610 1619 800 1650 413 1524 906 1242 1262 1701 1311 1658 1317 1572 1129 1251 280 1777 1090 1189 101 250 1183 1647 494 1651 125 1327 734 806 160 454 1235 1473 594 1462 477 1653 1499 1564 101 150 532 1783 323 996 273 1660 673 1712 467 1336...
output:
549744152 65443958 947942184 206882269 294225986 509279775 607027484 831437377 284527138 644981110 136872723 346562272 805001638 757538080 142994739 636604032 235915153 191478222 420266891 316351348 160427563 981024549 295451063 206574440 169724015 998341320 504596619 257672157 680397426 92774892 71...
result:
ok 1850 lines
Test #5:
score: 4.34783
Accepted
time: 32ms
memory: 14056kb
input:
2000 400000 241 1037 978 1342 9 64 31 1222 483 665 176 581 1145 1835 1009 1936 537 1738 262 1732 392 1222 980 1718 97 1196 308 718 1631 1889 1030 1135 699 906 1023 1910 559 1724 665 1147 802 1614 1463 1557 1316 1957 947 1045 149 1609 347 732 56 1061 785 869 1250 1944 1383 1925 354 1073 831 1760 1534...
output:
428584967 853696809 667720506 975776658 613997725 280681240 762326600 836660782 945565587 21802756 48298370 706692487 29850855 37434048 68408996 234559045 907749622 896456014 561515961 973380422 916649463 707794413 401041258 778156875 849085253 17889463 857462030 784618110 817657038 64596101 7692989...
result:
ok 2000 lines
Test #6:
score: 4.34783
Accepted
time: 32ms
memory: 12344kb
input:
2000 400000 1048 1063 489 1920 501 736 126 227 180 966 888 1730 805 1772 910 1378 1228 1779 1209 1668 858 1055 1441 1667 1669 1768 1422 1838 377 609 405 725 241 1865 1591 1630 60 958 842 1905 730 1585 525 1217 542 558 223 379 111 1100 55 58 279 1227 1575 1897 1064 1141 1486 1533 118 1114 273 1802 10...
output:
641665157 685662125 825479657 966538097 219313730 883712252 187472017 16366160 220230798 504417927 235091186 293280397 785637202 932264358 108016660 356410712 327753100 531134108 946247572 935205236 362307135 895503947 881786085 937896758 218247831 50934095 912430048 843142940 499745823 641925750 75...
result:
ok 2000 lines
Test #7:
score: 4.34783
Accepted
time: 27ms
memory: 12920kb
input:
10000 400000 778 2359 1787 3580 8076 8697 1493 4885 814 5277 6198 8246 5055 6524 2577 3582 2255 5344 3106 3900 3091 7388 342 1489 1526 1578 780 797 1508 7293 1706 5591 1164 1891 2995 8016 858 9774 671 929 2899 7410 5487 9875 3550 9116 2498 9714 129 5909 81 9810 4951 8871 2138 5523 5182 6919 7544 883...
output:
306607485 354557005 419562436 821534565 499457937 990692740 997065436 842253218 654989398 395530031 678969497 426952205 865120555 466796228 975227137 828252181 931509808 254325238 955840676 199846658 636113735 930702132 67018751 666650714 867860430 656640921 834367865 509142489 396370034 930228881 2...
result:
ok 10000 lines
Test #8:
score: 4.34783
Accepted
time: 35ms
memory: 15668kb
input:
10000 400000 2990 6494 3213 8324 4148 9810 2321 6780 2887 5978 7186 7772 1435 7364 3345 4004 3916 6828 9566 9643 1363 2996 3515 8342 2790 6713 5966 9814 7748 7847 5730 6344 6782 8035 6962 9136 4092 7456 1053 7773 6298 8474 1037 6022 1292 3965 3396 9610 3585 9769 7463 8127 1815 2443 100 8984 1595 373...
output:
975316062 542579352 727559560 723829159 298813148 12051258 878064332 477203534 138056953 97530905 160495814 851008971 91019396 16043161 968561324 643232081 842737176 357447407 570000265 817447506 599793667 669252516 812059685 200650064 850431927 314594072 899718010 925965935 893772252 140841076 8953...
result:
ok 10000 lines
Test #9:
score: 4.34783
Accepted
time: 31ms
memory: 14476kb
input:
10000 400000 9197 9788 102 839 1143 5723 3554 4275 3868 9539 771 6032 3553 9453 371 4184 207 5903 849 6720 1139 6924 4014 4567 4841 8626 9890 9922 2021 3345 669 7509 2799 5842 6817 8841 2893 9707 1205 4562 1890 4998 3513 3766 4296 9439 2714 5367 5833 6209 3437 8536 5262 5992 6211 9487 5293 7654 5407...
output:
26763223 464847037 896797844 639846766 904699183 899022503 568296288 540809640 189600354 146698976 235126761 927635052 852639813 525007860 654379588 978619428 515253258 641511742 556158560 821074540 915063153 557455914 884623345 11374121 571825860 978547089 684950861 281421065 788244517 912871115 94...
result:
ok 10000 lines
Test #10:
score: 4.34783
Accepted
time: 35ms
memory: 14524kb
input:
10000 400000 2674 2998 5213 9617 2470 4209 1527 8263 2494 6282 1447 7812 8231 8955 4117 9882 931 7152 4191 9268 5231 5650 235 6429 1950 3881 1366 5777 9020 9644 4884 9024 3972 9852 4581 5252 1683 6740 1466 5774 2931 3731 2549 4118 6783 9068 2707 8726 4902 8947 1306 4288 2835 4072 4512 9282 592 6080 ...
output:
208620425 91579638 987741247 459991829 565712878 787196471 679027617 730221442 966401868 991688222 252457204 764960804 532119648 106184877 564011161 240286003 887083266 390943510 728384424 905116303 809969618 995287645 297704936 365449563 720222634 636558925 752993756 798333316 106092974 183301463 6...
result:
ok 10000 lines
Test #11:
score: 4.34783
Accepted
time: 103ms
memory: 24652kb
input:
200000 199999 7451 7452 7452 7453 7453 7454 7454 7455 7455 7456 7456 7457 7457 7458 7458 7459 7459 7460 7460 7461 7461 7462 7462 7463 7463 7464 7464 7465 7465 7466 7466 7467 7467 7468 7468 7469 7469 7470 7470 7471 7471 7472 7472 7473 7473 7474 7474 7475 7475 7476 7476 7477 7477 7478 7478 7479 7479 7...
output:
951830658 76871107 253999304 926030194 287340802 943977009 579152290 252550201 836492598 809061610 499715043 689395011 51163306 952045117 426363743 458068350 293809999 471694808 88738428 274642590 921876023 909641005 575110280 741510102 156091263 441244966 319714958 7257195 544615180 171063366 59774...
result:
ok 200000 lines
Test #12:
score: 4.34783
Accepted
time: 98ms
memory: 24768kb
input:
200000 199999 63667 63668 63666 63667 63665 63666 63664 63665 63663 63664 63662 63663 63661 63662 63660 63661 63659 63660 63658 63659 63657 63658 63656 63657 63655 63656 63654 63655 63653 63654 63652 63653 63651 63652 63650 63651 63649 63650 63648 63649 63647 63648 63646 63647 63645 63646 63644 6364...
output:
835339339 835339339 239004210 923402065 999909862 862032317 947356606 619465112 626698446 215088900 756359537 292394631 107853818 699250184 33039735 77548558 626777306 229842839 388628535 418019894 705975186 336937203 23914927 278665729 856410991 33077404 126298111 946840469 723681606 814509286 1485...
result:
ok 200000 lines
Test #13:
score: 4.34783
Accepted
time: 109ms
memory: 24400kb
input:
200000 199999 67602 67603 67603 67604 67604 67605 67605 67606 67606 67607 67607 67608 67608 67609 67609 67610 67610 67611 67611 67612 67612 67613 67613 67614 67614 67615 67615 67616 67616 67617 67617 67618 67618 67619 67619 67620 67620 67621 67621 67622 67622 67623 67623 67624 67624 67625 67625 6762...
output:
810957719 629719751 333040906 156773202 932815927 713953076 365936610 925404772 549926770 727063458 451109611 851876519 96111607 537635439 578115171 868839399 268863225 830429719 692888982 418937735 327498919 527359604 301967293 441565228 406267333 374028518 892554184 120461386 459551782 84151394 30...
result:
ok 200000 lines
Test #14:
score: 4.34783
Accepted
time: 116ms
memory: 25244kb
input:
200000 199999 2337 2338 2338 2339 2339 2340 2340 2341 2341 2342 2342 2343 2343 2344 2344 2345 2345 2346 2346 2347 2347 2348 2348 2349 2349 2350 2350 2351 2351 2352 2352 2353 2353 2354 2354 2355 2355 2356 2356 2357 2357 2358 2358 2359 2359 2360 2360 2361 2361 2362 2362 2363 2363 2364 2364 2365 2365 2...
output:
980868389 980868389 384533260 68931108 145438905 7561360 92885649 764994162 772227496 360617950 901888587 437923681 253382868 844779234 178568785 223077608 772306356 375371889 534157585 563548944 851504236 482466253 169443977 424194779 1940034 178606454 271827161 92369512 869210656 960038336 2941003...
result:
ok 200000 lines
Test #15:
score: 4.34783
Accepted
time: 153ms
memory: 24812kb
input:
200000 400000 69354 168457 53989 75309 167264 182311 66623 153345 78557 193855 39834 44704 9200 79045 43416 65994 4303 34947 8935 189925 6103 89459 101253 157016 45650 184018 35685 75748 15843 125556 19443 45770 113826 149007 44321 105930 40005 147158 29900 135638 94100 128382 100444 146374 32168 10...
output:
980942741 804695718 612385128 349200631 896602227 862565338 411143563 292364750 568301917 743936592 557057606 922774599 276217389 7809843 492274921 68676548 661992080 397473997 654794100 176751659 503712759 368442304 570799796 179245377 204645292 357736561 229636548 428519939 9230227 435837484 23927...
result:
ok 200000 lines
Test #16:
score: 4.34783
Accepted
time: 144ms
memory: 24768kb
input:
200000 400000 138624 188139 79804 145333 51034 64229 30009 168087 6271 37660 147448 199738 23702 134452 28418 168836 39386 69950 84025 161110 17532 18064 27783 55968 20187 168760 118383 199140 102438 157309 118681 195228 159214 169861 32061 38787 60647 116055 20433 90598 28807 92771 172240 192922 63...
output:
127421299 499339865 988632833 124420137 48155649 573272426 127826765 619003944 991062374 455732422 962927821 330406387 664385106 376869393 536778433 682269805 202076639 557602042 131366107 950535154 406460282 762787545 95017448 655380300 53543537 951789784 248815712 142883676 239947402 4920955 10397...
result:
ok 200000 lines
Test #17:
score: 4.34783
Accepted
time: 150ms
memory: 24804kb
input:
200000 400000 34810 153024 35972 190888 59728 185676 166424 184755 27926 163241 28534 65646 101912 147390 29823 92536 84139 146163 152112 166895 113960 168126 29948 56097 45071 130904 19325 181534 31189 104284 162661 182196 71097 74296 149370 167685 59342 70987 39270 171441 97471 148464 85624 103938...
output:
136433763 915830060 262732981 745639663 303431756 415332921 605055535 231458097 964028758 432489605 985722836 645374809 624617560 723385926 22755675 75733691 855797490 256725209 914487644 526171941 244756175 698824876 676159788 649191612 561400946 924356917 656427543 501288871 257431481 746638928 20...
result:
ok 200000 lines
Test #18:
score: 4.34783
Accepted
time: 159ms
memory: 24820kb
input:
200000 400000 35062 73649 64791 143925 101462 165038 45693 153331 35409 107285 115961 145427 27783 67918 128531 145779 40834 199992 6065 6545 82539 134077 98906 185742 98690 194487 2224 50027 64160 75915 60576 191737 12703 75305 688 121173 88951 169823 54264 175492 133505 147184 4763 122735 125764 1...
output:
274235651 327160641 376140781 563126514 180503361 250736042 144877352 213200456 488756024 763333023 181697113 374860696 659569444 764892598 522552508 934767222 265857965 991242639 781750745 676174464 542581516 33204703 363961571 699428952 402939772 533132670 725521870 581723207 913911031 68489947 63...
result:
ok 200000 lines
Test #19:
score: 4.34783
Accepted
time: 162ms
memory: 24776kb
input:
200000 400000 69557 165536 76893 85294 93444 103801 29994 156596 29213 189223 69458 153440 74841 146861 29704 188158 93014 94262 54121 109853 21949 175512 40057 110336 75221 140758 72007 101575 63144 143155 3684 33946 64171 154358 40445 165178 126511 193846 83335 148593 13665 189586 88155 88304 6597...
output:
910178652 256068862 306904695 138183312 949235854 359996419 99609787 349053170 493267690 796524392 943346251 974457058 171189806 274705952 181082892 212439381 411786935 914588926 827801552 950085598 798160466 96429736 272857193 412519917 726356742 686929478 275873437 97673040 684907330 868941569 594...
result:
ok 200000 lines
Test #20:
score: 4.34783
Accepted
time: 139ms
memory: 24872kb
input:
200000 400000 28718 41339 54122 85143 3679 8439 18874 46011 25879 171685 121889 144440 108371 156983 28028 98211 40126 189724 42583 159032 164412 187758 63293 91419 68633 141485 89943 102221 27494 35556 51414 117816 36855 56519 117586 160276 73971 140740 48995 112286 8979 197943 123524 193900 39752 ...
output:
548609526 849303372 468452676 413226689 723910882 333487790 145917516 447962709 595146819 48266656 777679752 585957360 296170226 955187780 898946431 762569608 37442310 960143577 376435560 18595779 396587575 854098679 391778014 618078744 459276383 862367891 223687362 691448253 987739778 27853636 7699...
result:
ok 200000 lines
Test #21:
score: 4.34783
Accepted
time: 141ms
memory: 24836kb
input:
200000 400000 11002 138561 94075 162193 143010 159774 26390 37531 31488 105313 8964 172286 2817 77514 100811 164684 157292 161979 7253 85764 25478 92507 47628 57195 8862 184895 18776 187888 10464 133759 81742 121864 36414 156894 22325 166702 63650 76310 152860 157752 105260 153534 6695 199012 5335 1...
output:
183101945 477391316 579143473 745607626 566770270 647705914 738892983 850434610 667266425 737855227 981745119 72876316 25173327 403556021 579889322 376530602 584767851 545947019 590266471 872043926 386132189 836673287 493214553 26928813 34878971 947715978 790061785 605617788 17996392 39083868 828927...
result:
ok 200000 lines
Test #22:
score: 4.34783
Accepted
time: 147ms
memory: 24816kb
input:
200000 400000 84237 117430 19258 38279 44815 191998 118424 176164 15893 49383 30974 187447 35089 172696 30293 147182 51323 181825 49658 148610 84750 105002 34271 62542 43135 119118 45822 195660 84354 191883 24867 191111 154041 198116 42634 45892 16524 91048 9018 60261 50462 61258 55036 83529 82217 1...
output:
260219076 779350854 452033081 274222957 414217419 409096203 469909626 729500693 78835757 860394668 494187084 987059963 403284526 524087166 123230914 599423186 85737476 811310158 380575266 482866334 438514557 604849869 451598270 373571499 617495537 255220484 248144120 378459121 928652725 968887624 52...
result:
ok 200000 lines
Test #23:
score: 4.34783
Accepted
time: 146ms
memory: 24808kb
input:
200000 400000 24562 95258 68424 125123 67323 79526 88909 98334 98895 197405 12362 62753 139962 183338 41159 87038 61475 164241 107557 112478 37443 39227 64899 192102 27380 148780 35258 55995 127415 129946 119755 157839 48585 164932 11086 131612 119792 152566 39792 197004 6593 68750 60413 183111 1122...
output:
452226695 320436644 907496417 101005960 766468811 983558319 381672659 237135897 204029257 136656705 825756801 359336059 606490495 104483517 860430087 679815544 9937494 59046632 19114201 165852227 496166447 459895066 710418430 424589910 571471625 983599217 380055938 435665007 534580856 845190803 1104...
result:
ok 200000 lines