QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#441424 | #8531. A Graph Problem | green_gold_dog# | 13.043478 | 76ms | 4240kb | C++14 | 4.0kb | 2024-06-14 15:09:27 | 2024-06-14 15:09:28 |
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;
dp[v] += x;
}
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);
}
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() {
prec(get(0));
}
};
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 << '\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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.34783
Accepted
time: 0ms
memory: 3536kb
input:
3 2 1 2 2 3
output:
12 12 21
result:
ok 3 lines
Test #2:
score: 4.34783
Accepted
time: 1ms
memory: 3620kb
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: 1ms
memory: 3600kb
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: 2ms
memory: 3728kb
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:
1403514803 1446991809 465829116 1168795432 282143423 915031804 938173085 44530518 1306022642 502000109 45960809 985899639 750954950 582141768 1328554562 1449067192 1028201369 410173321 417764483 719955507 304176416 1454419730 1225304972 987891628 711586233 789588536 624133430 553812437 761065393 143...
result:
wrong answer 1st lines differ - expected: '549744152', found: '1403514803'
Test #5:
score: 0
Wrong Answer
time: 40ms
memory: 3976kb
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:
289685916 492875335 1763053259 1302247759 809248098 610103984 893466676 1088079328 641986855 478448675 864788634 1311832005 620336218 249072794 958256261 889520009 980441343 687025955 430478767 306689776 397562524 330717272 310211411 385314534 809603020 616023571 325375486 752660714 983284074 661278...
result:
wrong answer 1st lines differ - expected: '428584967', found: '289685916'
Test #6:
score: 0
Wrong Answer
time: 42ms
memory: 3972kb
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:
1408045378 905968234 85399990 982555832 830907544 544411808 1582932319 422478917 873569776 1138992627 1451759513 369124668 708167315 472652982 896588136 869807285 948873994 286395307 711941193 511711107 1058918040 1078155006 872998802 1234007574 1873425193 1250061168 1669692324 466449181 182678936 1...
result:
wrong answer 1st lines differ - expected: '641665157', found: '1408045378'
Test #7:
score: 0
Wrong Answer
time: 74ms
memory: 4156kb
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:
788553983 325530506 1328050467 896709357 52936264 2250607799 80129771 202710247 2134221056 306567646 1295023436 579880163 581016319 260964477 325187445 1965659681 869817873 1980047834 100005613 1041390363 727644373 341499899 1345236736 635731184 491344750 1009841910 831580633 272098323 237006420 124...
result:
wrong answer 1st lines differ - expected: '306607485', found: '788553983'
Test #8:
score: 0
Wrong Answer
time: 73ms
memory: 4184kb
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:
1195729257 2296486952 605813094 1410534924 588666011 1124382980 2005143197 421163042 333091423 1343533510 935931686 1603814979 1403489216 295820323 940962560 442702795 162524914 155380493 1100137501 98491654 906349862 1293753418 207170808 1122957735 215297328 1297323431 638200375 935918996 384225390...
result:
wrong answer 1st lines differ - expected: '975316062', found: '1195729257'
Test #9:
score: 0
Wrong Answer
time: 74ms
memory: 4240kb
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:
162431607 1138797731 211236505 582349508 1730505307 1832706306 365606558 586293699 512653345 1734397685 1013278872 1028102381 794713593 1329531429 327512880 708351437 782682479 342204124 1755707098 1068995211 1193597755 1264559902 106046446 605940913 989526790 975637651 1631150340 1453630394 1316088...
result:
wrong answer 1st lines differ - expected: '26763223', found: '162431607'
Test #10:
score: 0
Wrong Answer
time: 76ms
memory: 4120kb
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:
604372381 399887452 330885153 612351429 982650804 328977737 715169815 514460027 2580053264 1026203813 912162119 862730162 2016183582 375516553 1525323197 535683109 726403661 232271785 262858591 913048138 525256234 1817287132 1773651603 1061354186 789042329 899143672 322226860 1190382536 107153084 94...
result:
wrong answer 1st lines differ - expected: '208620425', found: '604372381'
Test #11:
score: 0
Time Limit Exceeded
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:
result:
Test #12:
score: 0
Time Limit Exceeded
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:
result:
Test #13:
score: 0
Time Limit Exceeded
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:
result:
Test #14:
score: 0
Time Limit Exceeded
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:
result:
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...