QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#441467 | #8531. A Graph Problem | green_gold_dog# | 13.043478 | 846ms | 25276kb | C++23 | 4.2kb | 2024-06-14 15:27:06 | 2024-06-14 15:27:06 |
Judging History
answer
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
T square(T a) {
return a * a;
}
template<>
struct std::hash<pair<ll, ll>> {
ll operator() (pair<ll, ll> p) const {
return ((__int128)p.first * MOD + p.second) % INF64;
}
};
struct DSU {
vector<ll> p, p10, sz;
vector<ll> mul, add, dp;
vector<vector<ll>> sons;
DSU(ll n) {
sz.resize(n, 1);
p10.push_back(1);
p.resize(n);
sons.resize(n);
mul.resize(n, 1);
add.resize(n, 0);
dp.resize(n);
for (ll i = 0; i < n; i++) {
p[i] = i;
dp[i] = 0;
p10.push_back(p10.back() * 10 % MOD);
}
}
void addv(ll v, ll x) {
add[v] += x;
add[v] %= MOD;
dp[v] += x;
dp[v] %= MOD;
}
void mulv(ll v, ll x) {
add[v] *= x;
add[v] %= MOD;
mul[v] *= x;
mul[v] %= MOD;
dp[v] *= x;
dp[v] %= MOD;
}
void push(ll v) {
for (auto i : sons[v]) {
mulv(i, mul[v]);
addv(i, add[v]);
}
mul[v] = 1;
add[v] = 0;
}
ll get(ll v) {
return (p[v] == v ? v : get(p[v]));
}
void unite(ll a, ll b, ll num) {
ll pa = get(a), pb = get(b);
if (pa == pb) {
return;
}
if (sz[pa] > sz[pb]) {
swap(pa, pb);
swap(a, b);
}
ll dpa = dp[a], dpb = dp[b];
mulv(pa, 10);
addv(pa, num);
mulv(pb, 10);
addv(pb, num);
mulv(pa, p10[sz[pb] - 1]);
addv(pa, dpb);
mulv(pb, p10[sz[pa] - 1]);
addv(pb, dpa);
push(pa);
p[pb] = pa;
sz[pa] += sz[pb];
sons[pa].push_back(pb);
}
void prec(ll v) {
push(v);
for (auto i : sons[v]) {
prec(i);
}
}
void pall() {
for (ll i = 0; i < p.size(); i++) {
if (p[i] == i) {
prec(i);
}
}
}
};
void solve() {
ll n, m;
cin >> n >> m;
DSU d(n);
for (ll i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
a--;
b--;
d.unite(a, b, i + 1);
}
d.pall();
for (auto i : d.dp) {
cout << i % MOD << '\n';
}
}
int main() {
if (IS_FILE) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
if (IS_TEST_CASES) {
cin >> t;
}
for (ll i = 0; i < t; i++) {
solve();
}
}
详细
Test #1:
score: 4.34783
Accepted
time: 1ms
memory: 3588kb
input:
3 2 1 2 2 3
output:
12 12 21
result:
ok 3 lines
Test #2:
score: 4.34783
Accepted
time: 0ms
memory: 3656kb
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: 0ms
memory: 3508kb
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: 0
Wrong Answer
time: 0ms
memory: 3984kb
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:
300498008 44738656 846907192 971270751 986735187 975839000 553154760 435257470 586233856 636697174 207414300 835476846 661912472 270541114 817240224 108168225 417202375 626306508 683070419 284243242 873633273 70272829 774044973 66518111 586016372 995023077 36987482 499540942 357286438 837941757 3651...
result:
wrong answer 1st lines differ - expected: '549744152', found: '300498008'
Test #5:
score: 0
Wrong Answer
time: 846ms
memory: 3876kb
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:
584934141 61112672 575099293 911983567 163177196 761364487 220551953 748333000 744363780 590222409 665765485 800909842 574216114 353528852 885805412 577143099 285154295 149090302 163488143 839123170 679447920 378494677 810204407 103035994 844908975 496140625 566487411 698100821 788947662 404915668 2...
result:
wrong answer 1st lines differ - expected: '428584967', found: '584934141'
Test #6:
score: 0
Wrong Answer
time: 778ms
memory: 3800kb
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:
397349728 234866760 860935868 389305316 289663607 461574415 79714867 523030083 49743711 744515305 576111307 887928884 243215981 149881987 97151389 446935858 657409021 721013032 20397499 879050395 182822755 163604258 754220645 414410196 851706867 186420123 336003665 532283750 343070368 32866860 56237...
result:
wrong answer 1st lines differ - expected: '641665157', found: '397349728'
Test #7:
score: 0
Time Limit Exceeded
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:
result:
Test #8:
score: 0
Time Limit Exceeded
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:
result:
Test #9:
score: 0
Time Limit Exceeded
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:
result:
Test #10:
score: 0
Time Limit Exceeded
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:
result:
Test #11:
score: 0
Wrong Answer
time: 47ms
memory: 24516kb
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:
913683359 38723808 215852005 887882895 249193503 905829710 541004991 214402902 798345299 770914311 461567744 651247712 13016007 913897818 388216444 419921051 255662700 433547509 50591129 236495291 883728724 871493706 536962981 703362803 117943964 403097667 281567659 969109903 506467881 132916067 559...
result:
wrong answer 1st lines differ - expected: '951830658', found: '913683359'
Test #12:
score: 0
Wrong Answer
time: 48ms
memory: 25276kb
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:
609757402 609757402 13422273 697820128 774327925 636450380 721774669 393883175 401116509 989506970 530777600 66812694 882271888 473668247 807457805 851966628 401195369 4260902 163046598 192437957 480393249 111355266 798332997 53083792 630829054 807495474 900716181 721258532 498099669 588927349 92298...
result:
wrong answer 1st lines differ - expected: '835339339', found: '609757402'
Test #13:
score: 0
Wrong Answer
time: 36ms
memory: 24816kb
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:
448367046 342165029 795845694 123173034 935166234 75808126 322839139 832782049 962051534 186663050 385457553 533707926 252777685 442648192 966594695 91986591 838687188 867021294 397156712 799967043 476143958 352161967 888342924 643673483 765701856 306725707 557878061 112052164 713811549 965101037 44...
result:
wrong answer 1st lines differ - expected: '810957719', found: '448367046'
Test #14:
score: 0
Wrong Answer
time: 35ms
memory: 24588kb
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:
343455642 343455642 747120520 431518368 508026165 370148620 455472909 127581415 134814749 723205210 264475840 800510941 615970128 207366487 541156045 585664868 134893609 737959149 896744845 926136204 214091489 845053513 532031237 786782039 364527294 541193714 634414421 454956772 231797909 322625589 ...
result:
wrong answer 1st lines differ - expected: '980868389', found: '343455642'
Test #15:
score: 0
Time Limit Exceeded
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:
result:
Test #16:
score: 0
Time Limit Exceeded
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:
result:
Test #17:
score: 0
Time Limit Exceeded
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:
result:
Test #18:
score: 0
Time Limit Exceeded
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:
result:
Test #19:
score: 0
Time Limit Exceeded
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:
result:
Test #20:
score: 0
Time Limit Exceeded
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:
result:
Test #21:
score: 0
Time Limit Exceeded
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:
result:
Test #22:
score: 0
Time Limit Exceeded
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:
result:
Test #23:
score: 0
Time Limit Exceeded
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...