QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#441550#8531. A Graph Problembashkort#13.043478 74ms6368kbC++201.7kb2024-06-14 16:09:402024-06-14 16:09:41

Judging History

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

  • [2024-06-14 16:09:41]
  • 评测
  • 测评结果:13.043478
  • 用时:74ms
  • 内存:6368kb
  • [2024-06-14 16:09:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int MOD = 1e9 + 7;

int inverse(int x) {
    return x == 1 ? 1 : 1LL * (MOD - MOD / x) * inverse(MOD % x) % MOD;
}

void madd(int &x, int y) {
    if ((x += y) >= MOD) {
        x -= MOD;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<int> fa(n), tag(n), sz(n, 1), power(n + 2, 1);
    iota(fa.begin(), fa.end(), 0);
    power[1] = inverse(10);
    for (int i = 2; i <= n; ++i) {
        power[i] = 1LL * power[1] * power[i - 1] % MOD;
    }

    auto find = [&](int x) -> pair<int, int> {
        int sum = tag[x];
        while (x != fa[x]) {
            madd(sum, tag[x = fa[x]]);
        }
        return {x, sum};
    };

    auto unite = [&](int x, int y, int e) {
        int sx, sy;
        tie(x, sx) = find(x), tie(y, sy) = find(y);
        if (x == y) {
            return;
        }
        if (sz[x] < sz[y]) {
            swap(x, y);
        }
        madd(tag[x], 1LL * power[sz[x]] * sy % MOD);
        madd(tag[x], 1LL * power[sz[x] - 1] * e % MOD);
        madd(tag[y], 1LL * power[sz[y]] * sx % MOD);
        madd(tag[y], 1LL * power[sz[y] - 1] * e % MOD);
        madd(tag[y], MOD - tag[x]);
        sz[x] += sz[y];
        fa[y] = x;
    };

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        unite(a, b, i + 1);
    }

    int p = 1;
    for (int i = 1; i < n - 1; ++i) {
        p = 10LL * p % MOD;
    }

    for (int i = 0; i < n; ++i) {
        cout << find(i).second * 1LL * p % MOD << '\n';
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
1 2
2 3

output:

12
12
21

result:

ok 3 lines

Test #2:

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

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

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

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:

153968809
418754566
503069244
599905803
801369107
986545117
393193833
225898419
842202356
758426648
796287203
609053728
952394477
498133355
601217230
123377151
415715121
253896726
960036223
180120857
818761606
66085745
298509207
77724067
646730911
274657582
882926289
974804826
392698729
790473264
58...

result:

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

Test #5:

score: 0
Wrong Answer
time: 41ms
memory: 3632kb

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:

460665660
398509816
127323673
289754249
899107593
175606736
44717017
688176575
938362568
512022716
292733026
581099638
166903261
936721719
676266551
224449633
779106808
761551057
162616168
828267159
53894578
230382875
499949893
962458941
347638944
972845581
556689126
811947897
871050233
985394632
36...

result:

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

Test #6:

score: 0
Wrong Answer
time: 40ms
memory: 3588kb

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:

722869752
157963442
25469310
640325135
829983543
828420098
935096444
361342597
546485891
116597838
443063497
615400290
581019373
738408681
532051981
327408492
484767067
245016289
589418124
118142945
426536937
792235664
305903675
772557650
60674123
797967133
175328831
211930516
342985303
702078059
65...

result:

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

Test #7:

score: 0
Wrong Answer
time: 38ms
memory: 3992kb

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:

267821586
389270752
320000969
861606911
554064624
624502058
899464552
778627433
146428765
68864515
774045953
17024256
805574935
718214385
134821861
224026964
636912349
448630223
66327030
1822974
964655416
502684195
278944689
561032290
598334923
987227066
303277374
508698844
716792742
492468659
19177...

result:

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

Test #8:

score: 0
Wrong Answer
time: 41ms
memory: 3748kb

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:

506892894
923010343
762471055
378190443
786804399
708647995
970283144
506435071
553009902
859134972
795085216
870148140
546379080
968439624
41228273
218275383
961376040
885295707
665348603
543812107
309860105
707967157
153884538
853356431
790893531
538062677
675726460
963000958
293529441
128473185
9...

result:

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

Test #9:

score: 0
Wrong Answer
time: 34ms
memory: 3636kb

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:

897210856
608176797
947889143
756948772
888765680
529909593
561551060
917238217
918348538
871603078
484330202
876000800
516904951
120740429
582719244
479039728
985071235
879429324
836542014
344255941
6781000
888844589
990389745
216840287
135384502
88281176
792030324
639593835
52530518
823103571
2174...

result:

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

Test #10:

score: 0
Wrong Answer
time: 38ms
memory: 3696kb

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:

598271699
444785685
409137499
991554642
952418013
876559988
936870636
855234833
76706126
981035815
108087043
779985660
211222044
254108588
588358276
953638337
321890022
467350183
496613747
338318917
423027944
533272076
694940176
894522369
536470681
595722035
519690437
317655537
84268462
658547936
83...

result:

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

Test #11:

score: 0
Wrong Answer
time: 24ms
memory: 6312kb

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:

257998759
412403675
556593556
670060899
190580975
924409581
219134892
400942360
234721334
399715400
991860419
5515459
734276151
614146432
5644609
518741288
301017903
307043927
870063992
198024047
125380369
546662086
906825353
652080470
211017629
534410229
778707211
995548279
572832811
104578093
6811...

result:

wrong answer 1st lines differ - expected: '951830658', found: '257998759'

Test #12:

score: 0
Wrong Answer
time: 28ms
memory: 6264kb

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:

426807947
426807947
830472825
514870673
591378470
453500925
538825214
210933720
218167054
806557515
347828145
883863246
699322433
290718792
624508350
669017173
218245914
821311454
980097150
9488502
297443794
928405818
615383542
870134344
447879599
624546019
717766726
538309077
315150214
405977894
74...

result:

wrong answer 1st lines differ - expected: '835339339', found: '426807947'

Test #13:

score: 0
Wrong Answer
time: 32ms
memory: 6196kb

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:

191181365
540005539
76262880
589153847
891399927
317386374
282668840
659834300
345058055
3148695
312747059
365811291
137420973
933352722
361180461
994722217
552944179
33369555
489841876
246911501
411233490
660871813
891600689
212507281
227913012
115529188
997440875
544218044
958754642
241930556
1219...

result:

wrong answer 1st lines differ - expected: '810957719', found: '191181365'

Test #14:

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

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:

125291456
125291456
528956334
213354182
289861979
151984434
237308723
909417236
916650570
505041024
46311654
582346755
397805942
989202308
322991859
367500682
916729430
519794963
678580659
707972018
995927310
626889327
313867051
568617853
146363108
323029528
416250235
236792586
13633723
104461403
43...

result:

wrong answer 1st lines differ - expected: '980868389', found: '125291456'

Test #15:

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

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:

722727949
976217694
94934387
620520887
76751960
583650380
705348873
587123648
478018800
615164457
711225497
291254451
463028046
906202981
686302280
459540139
709359853
297897519
934146909
610757072
834744027
862378095
957920788
638212669
485467870
527188631
950076363
206083677
8943314
746809968
8823...

result:

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

Test #16:

score: 0
Wrong Answer
time: 74ms
memory: 6368kb

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:

110652442
28792191
82097740
83429379
579730211
560178958
958460521
722011575
981116595
888933640
140667824
511355203
988402155
76971260
428387045
80880730
455670068
199241762
163898847
841745850
901373119
224928376
384921483
577140982
330242508
583798288
625822388
422838897
681328666
357776534
32108...

result:

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

Test #17:

score: 0
Wrong Answer
time: 71ms
memory: 6200kb

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:

238078302
667530088
71725387
220701434
456273672
260747170
812860582
893972955
724247711
690235564
939289297
943321374
409572047
111637157
278066503
572604008
951855759
696534600
262029499
551529214
772861805
441413494
813351687
192915316
734373423
203330630
170139306
124546463
429424126
917249372
7...

result:

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

Test #18:

score: 0
Wrong Answer
time: 74ms
memory: 6296kb

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:

719145403
166348735
393038098
774481311
938618705
112791005
884494205
754228237
650902599
378498301
580127406
754503222
770100013
592784923
63164789
124860652
816128042
476782127
501716431
861470155
596210819
612766768
907198016
487050573
79802820
706599682
977661661
960589878
459368900
733087717
93...

result:

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

Test #19:

score: 0
Wrong Answer
time: 67ms
memory: 6244kb

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:

342808500
555574770
831957651
89723527
154028355
479671986
631094768
140510433
403293700
663484453
747324543
65048320
904926543
540834649
331500479
204071560
570761183
219446284
402137837
159772082
52666433
606917003
411803246
782782521
136852424
366856639
442081846
250148113
193264000
597121540
548...

result:

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

Test #20:

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

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:

599892467
829910717
177241750
439754527
800340987
700836817
830135579
613672427
254133033
801393614
616014588
278204961
494709869
193916815
72390062
592732968
546443998
261390845
682466989
310714674
356830057
957889656
495912661
617111634
344205707
535222756
580335373
938139874
448625655
861448739
6...

result:

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

Test #21:

score: 0
Wrong Answer
time: 74ms
memory: 6228kb

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:

208768735
598185949
868835624
871342949
928578181
200615254
275181050
963743173
496909225
441610473
858325030
398620700
504426864
906634621
505775331
490280353
53341564
374120933
834730154
213782458
242955104
394516733
897305873
325357204
802225553
522486947
526688995
921392050
956806341
479955334
1...

result:

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

Test #22:

score: 0
Wrong Answer
time: 67ms
memory: 6260kb

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:

956234620
773287717
465393198
993128466
167680592
40163208
592595684
877842436
118875212
789855573
687413574
999456647
104034873
134837428
178479253
115404075
235437034
113068918
218728578
633231619
617357301
297658248
778365716
227532556
372789419
841551414
46951558
589433343
941446363
493348500
99...

result:

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

Test #23:

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

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:

57737056
721914139
622007090
439912020
660122922
155529239
356325349
156807621
284097811
908498996
893279367
651355289
375822307
269822895
126093615
217688532
466560644
126765747
290936671
428981009
254087876
560074247
721028643
650548483
241914190
210996121
828895535
838056044
527772320
374118135
8...

result:

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