QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#441447#8531. A Graph Problemgreen_gold_dog#13.043478 76ms4404kbC++144.1kb2024-06-14 15:18:102024-06-14 15:18:10

Judging History

你现在查看的是最新测评结果

  • [2024-06-14 15:18:10]
  • 评测
  • 测评结果:13.043478
  • 用时:76ms
  • 内存:4404kb
  • [2024-06-14 15:18:10]
  • 提交

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);
                        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 << '\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: 0ms
memory: 3796kb

input:

3 2
1 2
2 3

output:

12
12
21

result:

ok 3 lines

Test #2:

score: 4.34783
Accepted
time: 0ms
memory: 3776kb

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: 3796kb

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: 3772kb

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:

1009288234
148024403
454366292
1996153054
913020965
457537985
549179882
982743531
1401412288
245361889
897086660
723174020
129813276
822500677
1122950137
1896289057
361606112
327694113
380133262
635508688
707478256
45987139
1374822983
332265399
66722634
691579427
277738877
606465626
925910136
246228...

result:

wrong answer 1st lines differ - expected: '549744152', found: '1009288234'

Test #5:

score: 0
Wrong Answer
time: 45ms
memory: 3808kb

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:

559211761
825020148
1751467904
887257775
539466597
624933433
14103636
1687769580
597276002
1401841520
442585360
1623887045
962608010
942737029
688898880
901238852
159526658
305540338
511506016
595372434
928504318
956526742
166744187
477052542
529070700
999131061
878458345
394624443
896035737
4623471...

result:

wrong answer 1st lines differ - expected: '428584967', found: '559211761'

Test #6:

score: 0
Wrong Answer
time: 41ms
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:

653958420
165043185
240612088
373674287
1158876536
537576802
1670083476
374973323
224194371
340616914
1253954815
141604486
48133072
217604298
135678241
417375981
853928245
451454700
626585054
149595285
1452038338
1506992971
837604371
950190021
1337727590
2158612257
844441494
14257461
1179771735
1384...

result:

wrong answer 1st lines differ - expected: '641665157', found: '653958420'

Test #7:

score: 0
Wrong Answer
time: 76ms
memory: 4344kb

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:

917599665
634435214
1440652516
891567458
574209592
3016538929
416518715
211386144
2025393261
497573216
944700542
659798951
35639379
680200092
715013783
1664689369
454051072
2007331159
884783611
1195314781
457976333
598679611
1262946295
1182439135
1459501868
1734129602
146774059
108889069
750535448
1...

result:

wrong answer 1st lines differ - expected: '306607485', found: '917599665'

Test #8:

score: 0
Wrong Answer
time: 70ms
memory: 4400kb

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:

214421162
995760340
602801629
1343668900
929545184
2004699754
2281211646
169364555
951104602
815478779
1106026177
2433962270
1447569428
896551608
660714613
482336470
594793925
702546880
1322056302
10914557
982546326
1841142273
617243776
518859826
73967561
1746794176
513744956
740271114
842915846
111...

result:

wrong answer 1st lines differ - expected: '975316062', found: '214421162'

Test #9:

score: 0
Wrong Answer
time: 76ms
memory: 4404kb

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:

713451941
1515922183
648591725
286696028
1494424167
2649939180
964652609
933575619
568389745
80294980
1128377455
1184323292
592456256
1378252671
881295262
134883180
1296667223
115691729
1777051708
1709911263
1457915019
1163712151
89539119
905720904
693140367
258386105
465805694
264881256
220369638
5...

result:

wrong answer 1st lines differ - expected: '26763223', found: '713451941'

Test #10:

score: 0
Wrong Answer
time: 70ms
memory: 4272kb

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:

236285082
916414507
30929236
751450674
885083348
611394971
819323734
676579479
1458494878
1548205075
895562514
1432055314
647616521
234046727
519497637
729799534
261517301
797420570
33674546
115561915
195378774
771197682
896846766
1035212634
700238925
882399944
817972652
1236179667
957212110
1179356...

result:

wrong answer 1st lines differ - expected: '208620425', found: '236285082'

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...

output:


result: