QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#441453#8531. A Graph Problemgreen_gold_dog#13.043478 194ms25396kbC++144.2kb2024-06-14 15:22:142024-06-14 15:22:14

Judging History

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

  • [2024-06-14 15:22:14]
  • 评测
  • 测评结果:13.043478
  • 用时:194ms
  • 内存:25396kb
  • [2024-06-14 15:22:14]
  • 提交

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 : p[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: 1ms
memory: 3780kb

input:

3 2
1 2
2 3

output:

12
12
21

result:

ok 3 lines

Test #2:

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

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

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: 1ms
memory: 3976kb

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: 36ms
memory: 3836kb

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: 32ms
memory: 3992kb

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
Wrong Answer
time: 37ms
memory: 4300kb

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:

664008569
560643989
537794986
343564865
96813312
512371116
564627677
103565727
270205598
470625692
804418880
813285136
822162948
115866791
358492782
91713587
49928287
921247147
482283295
565932836
946747562
489013664
27002367
527033097
99198233
667320392
820572545
78474843
451328452
127309050
611966...

result:

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

Test #8:

score: 0
Wrong Answer
time: 37ms
memory: 4592kb

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:

611441672
799149642
556015995
639026547
370127099
735631867
553678890
994997647
928542308
100666378
847144563
105950499
317282593
649331706
604432396
661208926
488698189
243406695
720891278
710875787
615355842
876407904
552187458
620689101
628388611
514734711
359864914
674622607
938963935
359846494
...

result:

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

Test #9:

score: 0
Wrong Answer
time: 37ms
memory: 4592kb

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:

191988668
394091673
913860374
232383330
891292551
508685685
524842000
494318379
359767063
383426640
97357337
97189400
314468077
633641023
354991915
740465493
721035766
853132653
236124464
656767602
891529099
781579311
950354550
43322217
174334842
761649403
796095326
712681901
948279509
507378827
349...

result:

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

Test #10:

score: 0
Wrong Answer
time: 29ms
memory: 4376kb

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:

830227311
360210711
815516888
471423737
831371864
508841959
109023160
91962058
214820366
587015130
904807801
935215022
435717093
530164739
302312224
609607240
262870287
576145254
71288690
936317020
218290109
896131665
567733837
742150315
746454837
725364584
169406514
140036073
240355891
406656962
59...

result:

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

Test #11:

score: 0
Wrong Answer
time: 47ms
memory: 24728kb

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: 46ms
memory: 25396kb

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: 42ms
memory: 24824kb

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: 44ms
memory: 24644kb

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
Wrong Answer
time: 179ms
memory: 24032kb

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:

790240430
426039757
77514390
547908783
956739313
621400648
88341821
295873719
603223300
184671864
32709909
943268628
775412294
477413756
224588868
929149460
820710125
530243453
893620334
269347529
298740795
529017223
858401243
340581712
220527582
710638023
677809381
830678724
873144586
615876175
496...

result:

wrong answer 1st lines differ - expected: '980942741', found: '790240430'

Test #16:

score: 0
Wrong Answer
time: 165ms
memory: 24108kb

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:

171891117
417937056
540564036
90209682
22494590
500564374
540756395
485619609
345042338
789931686
124479283
110707807
790723612
256963584
761048458
392777109
460865972
738905679
649888717
745857290
844114421
261014094
741395065
421851522
645275570
239877379
186808677
992704615
736026505
975707091
79...

result:

wrong answer 1st lines differ - expected: '127421299', found: '171891117'

Test #17:

score: 0
Wrong Answer
time: 149ms
memory: 24196kb

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:

826191341
23334122
514512692
223160260
773860821
921821528
990493329
486793957
329787046
267093948
619987050
124737727
7074172
426947822
521896883
187224535
261513481
461232903
673343319
325481582
686834003
342199532
581987616
918382024
760934389
175898269
293693477
638551826
828531445
204452116
389...

result:

wrong answer 1st lines differ - expected: '136433763', found: '826191341'

Test #18:

score: 0
Wrong Answer
time: 165ms
memory: 24060kb

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:

750888379
484088247
232081665
5699121
927844103
322994245
122110921
715774791
192846454
935247003
957117206
847539372
689868371
755491816
867294616
676277195
587769069
856917965
576564599
686863446
546088676
855174911
89698067
966661323
671414774
86709442
616216955
55358099
333420296
187881634
94697...

result:

wrong answer 1st lines differ - expected: '274235651', found: '750888379'

Test #19:

score: 0
Wrong Answer
time: 194ms
memory: 24020kb

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:

908002190
864716061
989948435
177123311
489853122
907753924
436126778
446198399
755374250
377583600
706947721
549362198
709395882
630378209
871439328
893214398
544227585
817529133
987526909
72094227
197516771
748103677
398216457
656198369
471581881
393800636
474606356
960133434
791908018
470921488
2...

result:

wrong answer 1st lines differ - expected: '910178652', found: '908002190'

Test #20:

score: 0
Wrong Answer
time: 179ms
memory: 24028kb

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:

989514957
995256113
353717944
843136346
139280051
191153150
925108892
566570680
102502694
392695156
356394274
855306629
509237141
462346874
5751015
50100185
78040516
501972767
905572042
563458247
961453990
161946137
650998476
414431423
815637807
747220740
264923267
211854248
645808068
639787776
7101...

result:

wrong answer 1st lines differ - expected: '548609526', found: '989514957'

Test #21:

score: 0
Wrong Answer
time: 190ms
memory: 24012kb

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:

266571357
824677005
525457690
324430531
951284257
603037341
706241466
83893951
512904994
878364711
387914879
719312083
802315030
565563146
321972463
829493808
417907219
671929827
879119813
189430876
61324577
742205854
260509838
810659518
221565879
263974461
120829171
231535635
632868212
984422619
76...

result:

wrong answer 1st lines differ - expected: '183101945', found: '266571357'

Test #22:

score: 0
Wrong Answer
time: 192ms
memory: 24020kb

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:

502888358
432772197
737200006
649821261
841500810
238645697
390866156
431937176
983151620
358441904
92090608
22791438
146914189
254296414
651729503
809668133
684532848
549586892
541061202
194811250
406113492
266234319
529798453
72054359
410481935
29940287
837637459
242513227
949247091
875675448
5582...

result:

wrong answer 1st lines differ - expected: '260219076', found: '502888358'

Test #23:

score: 0
Wrong Answer
time: 184ms
memory: 24104kb

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:

867180202
386313492
780759269
802378288
507820588
89541789
693393791
669648205
931450023
621903115
678673940
897049049
242519961
775784342
94434641
384683803
225016589
709615000
980131094
383829076
587890350
991652159
196487951
54761780
112988234
609899274
605705326
217168190
878149942
52214996
3150...

result:

wrong answer 1st lines differ - expected: '452226695', found: '867180202'