QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485490#7885. Information Spreaducup-team1198#AC ✓238ms43952kbC++204.3kb2024-07-20 18:35:442024-07-20 18:35:44

Judging History

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

  • [2024-07-20 18:35:44]
  • 评测
  • 测评结果:AC
  • 用时:238ms
  • 内存:43952kb
  • [2024-07-20 18:35:44]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int MOD = 998244353;

int add(int a, int b) {
  if (a + b < MOD)
    return a + b;
  return a + b - MOD;
}

int sub(int a, int b) {
  if (a >= b)
    return a - b;
  return a + MOD - b;
}

int mul(int a, int b) {
  return a * 1ll * b % MOD;
}

int pw(int a, int n) {
  int ans = 1;
  while (n) {
    if (n & 1) {
      ans = mul(ans, a);
    }
    n >>= 1;
    a = mul(a, a);
  }
  return ans;
}

const int MAXN = 100100;
int used[MAXN];
vector<pair<int, int>> G1[MAXN];

vector<pair<int, int>> Gtree[MAXN];
vector<pair<int, int>> from[MAXN];

const int K = 17;
int tin[MAXN];
int tout[MAXN];
int depth[MAXN];
int up[MAXN][K];
int up_prob[MAXN][K];
int ttime = 0;

void dfs1(int v, int par, int prob, int d) {
  tin[v] = ttime;
  ++ttime;
  up[v][0] = par;
  up_prob[v][0] = prob;
  depth[v] = d;
  used[v] = 1;
  for (auto [u, p] : G1[v]) {
    if (used[u] == 0) {
      Gtree[v].emplace_back(u, p);
      //cout << "tree " << v << ' ' << u << ' ' << p << '\n';
      dfs1(u, v, p, d + 1);
    } else if (used[u] == 1) {
      // skip
    } else {
      from[u].emplace_back(v, p);
      //cout << "left " << v << ' ' << u << ' ' << p << '\n';
    }
  }
  used[v] = 2;
  tout[v] = ttime;
}

int la(int v, int d) {
  for (int k = K - 1; k >= 0; --k) {
    if (d >= (1 << k)) {
      d -= 1 << k;
      v = up[v][k];
    }
  }
  return v;
}

int lca(int v, int u) {
  if (depth[v] >= depth[u])
    v = la(v, depth[v] - depth[u]);
  else
    u = la(u, depth[u] - depth[v]);
  if (v == u)
    return v;
  for (int k = K - 1; k >= 0; --k) {
    if (up[v][k] != up[u][k]) {
      v = up[v][k];
      u = up[u][k];
    }
  }
  return up[v][0];
}

bool is_par(int v, int u) {
  return tin[v] <= tin[u] && tout[u] <= tout[v];
}

vector<pair<int, int>> G2[MAXN];
int vals[MAXN];
int dp[MAXN];

void dfs2(int v) {
  dp[v] = vals[v];
  for (auto [u, p] : G2[v]) {
    dfs2(u);
    dp[u] = mul(dp[u], p);
    dp[v] = sub(1, mul(sub(1, dp[v]), sub(1, dp[u])));
  }
}

int calc_ans(int v) {
  vector<int> vertices;
  from[v].emplace_back(v, 1);
  vertices.emplace_back(0);
  for (auto [u, p] : from[v])
    vertices.emplace_back(u);
  sort(vertices.begin(), vertices.end(), [](int a, int b) {
    return tin[a] < tin[b];
  });
  int k = vertices.size();
  for (int i = 0; i + 1 < k; ++i) {
    int l = lca(vertices[i], vertices[i + 1]);
    vertices.emplace_back(l);
  }
  sort(vertices.begin(), vertices.end(), [](int a, int b) {
    return tin[a] < tin[b];
  });
  vertices.resize(unique(vertices.begin(), vertices.end()) - vertices.begin());

  vector<int> stack;
  for (auto u : vertices) {
    while (!stack.empty() && !is_par(stack.back(), u))
      stack.pop_back();
    if (!stack.empty()) {
      int par = stack.back();
      int w = 1;
      int tmp = u;
      int d = depth[u] - depth[par];
      for (int k = K - 1; k >= 0; --k) {
        if (d >= (1 << k)) {
          w = mul(w, up_prob[tmp][k]);
          tmp = up[tmp][k];
          d -= (1 << k);
        }
      }
      // edge from par to u with weight w
      G2[par].emplace_back(u, w);
    }
    stack.emplace_back(u);
  }
  for (int u : vertices)
    vals[u] = 0;
  for (auto [u, w] : from[v])
    vals[u] = w;
  dfs2(0);
  for (int u : vertices) {
    G2[u].clear();
  }
  return dp[0];
}


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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v, p, q;
    cin >> u >> v >> p >> q;
    int w = mul(p, pw(q, MOD - 2));
    --u;
    --v;
    G1[u].emplace_back(v, w);
  }
  dfs1(0, 0, 1, 0);
  for (int j = 1; j < K; ++j) {
    for (int i = 0; i < n; ++i) {
      up[i][j] = up[up[i][j - 1]][j - 1];
      up_prob[i][j] = mul(up_prob[i][j - 1], up_prob[up[i][j - 1]][j - 1]);
    }
  }
  for (int i = 0; i < n; ++i)
    cout << calc_ans(i) << '\n';
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7904kb

input:

4 4
1 2 1 2
2 3 1 2
2 4 1 2
4 3 1 1

output:

1
499122177
623902721
748683265

result:

ok 4 number(s): "1 499122177 623902721 748683265"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7720kb

input:

6 12
1 2 81804 95651
2 3 39701 95895
2 4 6178 17992
3 5 72756 84510
5 6 40007 83640
2 6 60491 92219
5 3 37590 47735
4 5 6867 20289
4 3 75051 93231
6 5 48102 54448
6 1 40190 45274
1 5 37010 60312

output:

1
947252499
124986918
535320090
929273289
551177734

result:

ok 6 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 9632kb

input:

18 30
1 2 68905 97125
1 3 4634 15693
1 4 10290 20648
1 5 3349 88594
3 6 6776 18167
3 7 10605 22278
7 8 19024 21234
5 9 45909 91947
5 10 26006 28250
6 11 27101 91945
3 12 12169 81869
3 13 24749 76281
11 14 26913 53860
5 15 19177 78025
13 16 4678 16370
8 17 85508 99363
9 18 43109 72047
8 6 52537 54614...

output:

1
587870937
729107040
419829520
781263615
722395838
476874266
990288185
398780004
622737504
42350433
892147725
146730128
761578250
835744402
215845842
965925643
564294682

result:

ok 18 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 7900kb

input:

18 30
1 2 75943 79132
2 3 71366 81207
2 4 45298 91205
1 5 56769 77801
4 6 26127 56376
1 7 66011 78966
3 8 80946 88346
2 9 9568 24994
6 10 2225 83583
5 11 9386 63588
3 12 41289 78921
6 13 40140 86437
8 14 62699 91243
8 15 76827 84260
2 16 6962 25417
2 17 12655 83595
6 18 5507 14512
6 2 22077 51469
11...

output:

1
328113262
106218218
766840757
344582337
817714536
944910097
393248539
687422113
619089925
489890410
890755006
954044621
932528195
500600461
833204505
99341252
566195076

result:

ok 18 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 9768kb

input:

18 30
1 2 17097 19510
2 3 21988 81902
2 4 8453 77124
4 5 30250 90144
5 6 11165 76424
4 7 55947 56208
5 8 78791 94128
5 9 78010 82732
8 10 5358 24580
7 11 10345 36204
10 12 16152 22243
11 13 17204 52825
9 14 82555 96382
12 15 66394 79800
8 16 8018 67783
10 17 52693 97751
12 18 7764 16842
14 4 93435 9...

output:

1
435471948
982521442
377784806
304001298
502002878
478007501
259240356
148904701
237801978
504821040
410990202
323240605
18558529
791387216
552250053
891711263
851639582

result:

ok 18 numbers

Test #6:

score: 0
Accepted
time: 1ms
memory: 7824kb

input:

18 30
1 2 69285 87481
2 3 68922 81015
1 4 48886 97199
2 5 79126 97249
4 6 71144 85123
2 7 15655 89243
5 8 1128 50013
2 9 24133 54960
5 10 6208 15682
4 11 18765 64033
4 12 55033 69217
4 13 26423 64553
5 14 44027 68207
5 15 46533 60406
9 16 6348 36629
8 17 30936 56927
10 18 47596 57526
6 8 25353 43192...

output:

1
280367895
371962012
101910295
509258335
464199582
360323211
498199788
49821733
633851440
654818083
530486940
536699754
427696010
795288298
670748355
823025056
871250468

result:

ok 18 numbers

Test #7:

score: 0
Accepted
time: 1ms
memory: 9948kb

input:

18 30
1 2 27859 34787
2 3 31637 69617
2 4 70045 71248
3 5 12500 25351
3 6 11071 25933
2 7 26071 40833
3 8 6910 7446
2 9 36737 52470
5 10 28563 37459
3 11 41176 42157
8 12 6448 35987
10 13 3488 30941
10 14 53363 59519
6 15 66886 73853
8 16 53709 97450
9 17 69439 72618
11 18 58931 86019
7 4 9503 23715...

output:

1
453395257
522907759
96906459
488011993
974428348
854013331
755272192
173939859
544804285
453530648
441844884
394352639
848189842
904928735
257733038
44516267
722615930

result:

ok 18 numbers

Test #8:

score: 0
Accepted
time: 3ms
memory: 8100kb

input:

1000 2000
1 2 13326 32784
2 3 3208 23501
3 4 25522 38316
3 5 25380 42111
5 6 29051 34637
5 7 3418 56771
7 8 45469 92989
1 9 2773 40049
4 10 3926 91990
10 11 11549 33351
11 12 1806 63778
6 13 19283 52120
4 14 19223 83500
9 15 30821 81695
9 16 1270 24327
3 17 58630 69764
9 18 29728 44589
1 19 13447 48...

output:

1
774169972
704801796
13270737
179732894
575097451
830339997
514050124
537569876
188598808
399224660
259353403
269443768
137569746
5933388
161343832
667011135
540997964
386090508
410310829
366498100
900723714
127439425
660550245
940594706
881539033
858314657
512224970
798634163
565455245
338944097
2...

result:

ok 1000 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 8064kb

input:

1000 1500
1 2 36718 52882
2 3 7011 29943
1 4 27360 79521
1 5 40511 69755
1 6 41557 64694
5 7 18421 59655
4 8 65991 94068
5 9 88428 98824
7 10 31179 89479
4 11 43558 89366
6 12 29451 56805
6 13 64835 70096
5 14 57265 67916
2 15 55660 59120
4 16 63716 74585
6 17 48712 77567
5 18 1660 65262
13 19 8263 ...

output:

1
73846147
846023247
190631520
931098450
90868721
406517767
638889114
777357623
253825671
741036249
875388184
679397950
887289357
298823323
926620395
25882799
757246577
770764525
981501372
170928637
978325822
660444034
794876669
43202730
732760512
338321347
251582555
212178062
646483136
682229245
92...

result:

ok 1000 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 10020kb

input:

1000 2000
1 2 71714 92590
1 3 10618 60360
1 4 57938 76294
2 5 278 35531
1 6 14933 85418
3 7 33469 42252
4 8 20349 64013
1 9 30780 96226
1 10 57702 80946
1 11 7118 80911
4 12 77723 86931
1 13 1221 56582
4 14 62249 84663
6 15 25529 47216
5 16 11619 77678
7 17 11867 91239
5 18 18249 79141
3 19 70866 82...

output:

1
922473090
99969516
748938407
294039687
198020372
392508428
77931924
323291167
320421905
998022277
167797877
105766408
520536156
597114522
210416202
617185911
982075292
215278088
489689988
717495083
613173534
447870582
285863373
409451769
462681783
852307129
707197014
451323685
363145088
111932368
...

result:

ok 1000 numbers

Test #11:

score: 0
Accepted
time: 3ms
memory: 7996kb

input:

1000 2000
1 2 12687 54693
2 3 17059 64164
2 4 24925 36283
4 5 10249 27921
5 6 4580 92199
4 7 22835 95121
6 8 56669 84535
5 9 6226 40862
7 10 25367 54088
7 11 14781 36925
11 12 14575 70750
11 13 22425 74558
13 14 10942 34081
9 15 32075 78176
10 16 63176 98412
16 17 74934 90816
13 18 11865 18542
16 19...

output:

1
672450162
604293713
826380536
307273414
661921002
843882877
352322727
598767091
805255880
524990940
661948181
456714763
292439580
139972761
748201543
939308944
182800663
389913084
947022398
382707444
324473556
721033636
723315872
332573577
364988605
806220570
822179792
388621062
741165291
31075252...

result:

ok 1000 numbers

Test #12:

score: 0
Accepted
time: 0ms
memory: 14000kb

input:

1000 2000
1 2 61311 72762
1 3 60162 88905
1 4 54081 60691
1 5 50125 58944
4 6 43969 68181
3 7 1405 43787
4 8 43622 92134
2 9 7279 15870
5 10 14076 15549
5 11 69104 86927
3 12 61077 76300
3 13 79755 97062
4 14 94626 97931
6 15 41404 50652
8 16 31080 56225
9 17 53000 61211
9 18 24179 36622
6 19 69951 ...

output:

1
595267094
283692052
281572952
14954021
365846555
774687550
652632526
122567655
550901743
7535611
368269143
571702780
43008952
682093264
823531489
576925191
318731905
210941318
833684709
435545025
940699024
597125473
664011309
127777518
680088519
528036416
170200267
441055044
462513693
273079565
24...

result:

ok 1000 numbers

Test #13:

score: 0
Accepted
time: 3ms
memory: 13880kb

input:

1000 2000
1 2 44290 68513
2 3 42256 92709
3 4 43125 74277
3 5 9315 77768
3 6 63131 80687
4 7 5437 57642
2 8 4556 93213
2 9 41707 77178
7 10 42801 51978
5 11 42940 76767
6 12 23961 69327
6 13 959 25930
7 14 46624 68391
4 15 24618 94050
9 16 18670 81339
6 17 40159 61043
13 18 12568 81250
5 19 64518 94...

output:

1
126133747
124464588
693248434
973272167
301345078
356505314
982411639
932239423
148947708
908278865
380095550
467958250
916627050
899363669
311670110
114259358
1740237
420940683
723839114
48128338
820825587
264984209
360746349
750431086
591515491
826107864
584793131
458245927
700322828
464573544
8...

result:

ok 1000 numbers

Test #14:

score: 0
Accepted
time: 233ms
memory: 42904kb

input:

100000 300000
1 2 87003 93125
2 3 77861 87154
3 4 2220 97511
3 5 14111 56121
5 6 21632 72223
2 7 27619 60289
3 8 6818 87040
1 9 4746 55070
1 10 40327 41392
5 11 12520 60692
9 12 32108 53702
7 13 63144 84746
10 14 9433 48040
10 15 15606 33848
12 16 14642 18038
8 17 18575 61531
9 18 19209 69501
8 19 5...

output:

1
19552191
196432994
403192484
289550948
260341665
378159607
568731877
593399893
586738667
567348511
262922674
91200919
434652712
356815960
870875746
506206150
0
0
0
75047378
289468221
0
521283454
566206397
0
580959568
420758912
133191739
201353191
289213048
42995716
604570564
975272726
0
843016461
...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 236ms
memory: 42808kb

input:

100000 300000
1 2 13487 24036
1 3 69563 98834
1 4 18163 53872
2 5 8929 74247
2 6 68783 99229
5 7 50699 71053
3 8 30537 66258
5 9 13542 24158
8 10 16652 56783
3 11 47071 65427
4 12 22423 58768
3 13 33885 72606
6 14 17159 79742
11 15 16674 23338
14 16 68520 99866
11 17 88462 94116
14 18 53724 92764
5 ...

output:

1
449741559
978296435
348307082
954478544
574240782
917154857
862552498
412951316
216156407
914616934
335813993
493963362
963999174
390994904
113269622
6717301
808462927
730182756
51292577
429251328
706840013
471062966
881609451
564897946
808488461
427496987
140740379
761056667
303123799
786328848
8...

result:

ok 100000 numbers

Test #16:

score: 0
Accepted
time: 229ms
memory: 41844kb

input:

100000 300000
1 2 17160 72522
2 3 63794 70109
3 4 20028 75506
2 5 11024 30763
4 6 15131 32968
3 7 27866 94913
2 8 4006 10939
2 9 19790 75927
5 10 42657 96045
4 11 12281 60574
2 12 19225 51478
7 13 14198 21662
1 14 20122 58493
7 15 32956 75798
9 16 27967 68543
3 17 14044 88081
4 18 61076 71667
10 19 ...

output:

1
270641743
705141114
809708881
831252732
802951222
506658157
192466843
475876480
333653532
710516555
86243704
0
322224055
0
775538769
960441361
533669475
0
684003529
165455238
606309922
84696975
91091355
0
0
586802897
430704774
0
801109977
0
0
745755782
59862818
710801916
0
0
0
0
0
0
496882386
0
77...

result:

ok 100000 numbers

Test #17:

score: 0
Accepted
time: 238ms
memory: 43952kb

input:

100000 300000
1 2 9555 37522
2 3 61811 99821
3 4 26690 76390
3 5 5841 48889
4 6 64769 92729
6 7 73872 93646
4 8 54437 63446
5 9 10051 50095
9 10 30892 48219
8 11 48720 74313
11 12 41793 48637
7 13 37299 68057
13 14 3266 90432
14 15 40129 83529
14 16 29419 78450
13 17 45012 83931
14 18 94931 95590
14...

output:

1
512583923
228478337
529227780
332861558
726400303
561609911
946358194
298516321
576890064
599441757
616009146
213127511
718606326
67554331
302107181
580042489
7682619
589794603
661780158
89315714
127051880
591508956
708093586
685960217
403825288
205235636
365961674
601777419
327444568
717561470
70...

result:

ok 100000 numbers

Test #18:

score: 0
Accepted
time: 238ms
memory: 42196kb

input:

100000 300000
1 2 58507 75551
2 3 74286 93365
3 4 85168 87716
2 5 17730 31180
2 6 58980 80251
4 7 38586 41726
2 8 50134 52856
2 9 28526 37704
3 10 30496 37259
6 11 41447 45933
6 12 33551 93368
3 13 30042 90601
7 14 16239 28467
3 15 35637 65151
9 16 68661 90776
9 17 48843 62879
7 18 81613 89515
5 19 ...

output:

1
735652088
340949800
52143427
228784636
740321993
904719669
105649781
534761779
797595918
544099805
739287866
633753034
390488335
285689168
866959956
647873851
766545205
126431319
994499485
129871894
866792149
965899402
360072944
28597072
497817985
919976782
48545731
309665815
993163708
116852848
7...

result:

ok 100000 numbers

Test #19:

score: 0
Accepted
time: 215ms
memory: 42752kb

input:

100000 300000
1 2 52998 78870
2 3 9413 85966
3 4 33183 36352
3 5 615 39450
2 6 36577 76811
4 7 49351 64806
3 8 47536 58390
4 9 7070 7524
3 10 22605 47760
6 11 9733 27826
3 12 62963 83683
7 13 76437 78460
7 14 23122 85359
7 15 23629 32475
5 16 43489 51652
12 17 21871 41015
12 18 12778 40473
4 19 3977...

output:

1
734273462
823806151
410354355
260816942
669088651
73906598
53640450
834343076
543848570
46159497
743986639
65359611
303319240
79507797
659502333
0
0
203992894
971766006
880013293
0
558045460
988275941
0
0
170248689
105673070
0
952145635
0
0
953515772
971063634
914736391
345636308
302037596
0
0
982...

result:

ok 100000 numbers

Test #20:

score: 0
Accepted
time: 94ms
memory: 33412kb

input:

100000 120000
1 2 1081 32280
1 3 109 65244
1 4 61851 79536
3 5 84212 95868
3 6 7203 20403
6 7 23680 68661
4 8 4991 68424
4 9 693 25220
3 10 17304 78695
3 11 73665 97038
10 12 59247 62495
7 13 67414 67872
9 14 6311 60236
13 15 30619 87118
10 16 42982 51225
2 17 9458 94496
8 18 24477 96361
9 19 15621 ...

output:

1
55138466
893881887
664755736
261275072
258769276
949066100
28475338
254330097
646222711
799955629
140623421
680157898
731095717
3189845
811472690
73085321
19894889
415906777
271730543
268492343
737476404
997622850
506225162
378944898
734977859
546046109
839601460
720083536
982919243
567624062
6897...

result:

ok 100000 numbers

Test #21:

score: 0
Accepted
time: 216ms
memory: 38064kb

input:

100000 300000
1 2 22360 59166
2 3 1812 21675
3 4 22364 68539
3 5 11133 22122
5 6 5057 63062
5 7 10129 52964
5 8 19046 70494
7 9 21853 23616
8 10 8012 55491
8 11 63601 74280
6 12 57092 95246
12 13 13995 65422
5 14 73121 88310
7 15 42924 77854
1 16 49667 70303
5 17 35037 41857
10 18 34863 35812
1 19 3...

output:

1
785928041
54211774
325793807
170748586
434007567
311386078
642327062
111671428
223257245
959949996
116803178
377623610
279960075
379956120
38332543
362477539
764239271
477438752
732667727
310020168
304617721
57328823
408902666
563172702
23376245
328403032
640911708
735093228
541407670
535740754
73...

result:

ok 100000 numbers

Test #22:

score: 0
Accepted
time: 86ms
memory: 30476kb

input:

100000 120000
1 2 11738 75373
2 3 13440 87768
2 4 26325 85254
2 5 11807 14290
2 6 73917 85384
4 7 1962 82812
2 8 24964 50372
3 9 23383 92411
6 10 20351 51213
4 11 55314 94661
4 12 16803 88521
7 13 36330 74638
3 14 24712 70173
3 15 23074 63662
9 16 9799 44757
4 17 38249 60870
7 18 43442 73863
10 19 6...

output:

1
294309448
938219528
438847701
410685907
12541559
561449567
683306756
86817164
117277234
197233052
835122860
20213338
334185535
919819737
590071890
215195816
258097562
850054591
971831507
334125221
44033602
124796716
419493001
93562289
61100048
584105754
833712643
772806489
645536441
929283925
2589...

result:

ok 100000 numbers

Test #23:

score: 0
Accepted
time: 93ms
memory: 33948kb

input:

100000 120000
1 2 41106 94170
2 3 19588 35007
2 4 38343 63322
3 5 2726 98106
5 6 41243 56474
4 7 57446 88411
6 8 77255 90467
6 9 27590 97433
5 10 25706 72801
8 11 21544 43449
6 12 14649 56155
10 13 80289 82454
13 14 47123 57400
10 15 50260 54397
8 16 30824 94789
10 17 9956 84429
13 18 22357 29779
13...

output:

1
128986273
566833145
989533147
605237962
835335953
587464797
181949523
326424483
715429842
92631273
174732452
162071876
636085943
29265286
487293249
402369931
95385307
720050281
758856393
119821909
996111681
305324912
32395296
821456844
200406249
615239282
739978185
367238272
35791843
292182308
847...

result:

ok 100000 numbers

Test #24:

score: 0
Accepted
time: 94ms
memory: 30500kb

input:

100000 120000
1 2 19559 71221
1 3 45962 55042
2 4 48290 88603
1 5 56930 62816
3 6 46706 64195
2 7 27659 69477
3 8 18306 60021
3 9 74438 86178
2 10 64146 74968
6 11 41244 79546
3 12 58259 85871
7 13 43380 68431
3 14 20056 55543
4 15 9358 66126
4 16 2021 3569
4 17 14884 83940
4 18 15952 90784
7 19 354...

output:

1
226164627
875463309
218870596
263895278
516395371
6975500
982351497
369356093
156685683
797150667
881126890
897825172
38533107
475475657
268263256
681762710
368157191
838073191
692717398
80045370
172050837
29662072
820233317
293401070
238401498
623655647
114034544
465400076
701796267
589966777
375...

result:

ok 100000 numbers

Test #25:

score: 0
Accepted
time: 204ms
memory: 35824kb

input:

100000 300000
1 2 9639 53653
1 3 51198 67528
3 4 91119 95291
2 5 72196 76380
2 6 48849 78218
5 7 15513 87616
6 8 34990 83809
6 9 84574 95598
8 10 916 92249
3 11 4723 78073
4 12 18957 31422
6 13 14554 76630
9 14 57288 77954
4 15 21620 46010
11 16 41784 76117
12 17 75704 90888
10 18 4939 51634
14 19 1...

output:

1
859911981
543322370
685299960
400182417
256448633
966735770
533764255
175661685
550821625
549641407
500866034
870707381
546855139
988899836
626439535
827931718
935592528
158683291
230274291
617567647
507556022
343570916
421039139
333591260
817195436
693240315
683446075
569467627
9292224
78267813
1...

result:

ok 100000 numbers

Test #26:

score: 0
Accepted
time: 88ms
memory: 35244kb

input:

100000 120000
1 2 22961 98093
1 3 76245 98373
2 4 25047 55537
4 5 8151 53796
5 6 86858 90525
6 7 30859 51571
6 8 24193 69887
1 9 16880 23038
1 10 56214 76970
5 11 12905 98878
7 12 54742 70343
6 13 62777 66078
9 14 13823 37436
13 15 82476 88694
5 16 46579 66393
8 17 1610 63248
9 18 67571 72577
11 19 ...

output:

1
80469095
516154830
458447741
423234741
634776970
775295871
727710794
56762745
155397738
158503182
38910420
594927642
380861616
234368084
13344242
151543413
557574579
621399324
888340312
981110205
359881115
153069039
767168439
627323765
466041925
477957580
394149514
169767656
821644750
168990965
70...

result:

ok 100000 numbers

Test #27:

score: 0
Accepted
time: 208ms
memory: 38088kb

input:

100000 300000
1 2 10780 78564
1 3 63578 90075
3 4 11898 76231
2 5 13372 26277
5 6 59071 68121
1 7 62335 64833
3 8 67690 78020
5 9 68058 71532
8 10 87470 97017
3 11 41465 85256
2 12 59807 60658
3 13 36818 85878
5 14 32091 58597
6 15 14553 71519
1 16 5981 7455
11 17 57480 58542
6 18 2084 95841
4 19 80...

output:

1
853655010
458798979
670809149
227971567
163035386
836497143
840878492
412454770
811852309
744474635
896180140
148017111
922603462
833537281
652430873
592610200
593579831
226590725
82996824
78556931
732461940
926226476
233060440
783574134
40394491
128638210
32872376
962694353
71506909
808718585
131...

result:

ok 100000 numbers

Test #28:

score: 0
Accepted
time: 89ms
memory: 32124kb

input:

100000 120000
1 2 16848 33694
1 3 62356 64780
1 4 42546 84033
2 5 7936 29752
3 6 28954 84285
1 7 6338 37860
4 8 1194 83534
3 9 45727 96783
2 10 9746 10284
1 11 43867 63871
4 12 19542 84748
7 13 20592 78892
5 14 4187 66053
1 15 71229 91652
1 16 2656 98097
8 17 9513 14631
5 18 67701 84727
9 19 24418 6...

output:

1
637094040
611274422
504770734
232313921
138899183
160151511
896067604
346692010
408767780
947668682
101647564
322958341
253335958
672136531
520792170
691101062
997589218
526567061
12122840
798335282
308673712
570760692
573605666
724593371
54335848
142901715
214445475
330261328
623797694
835970017
...

result:

ok 100000 numbers

Test #29:

score: 0
Accepted
time: 97ms
memory: 35484kb

input:

100000 120000
1 2 35487 96799
2 3 76461 78406
3 4 59563 98908
4 5 12637 91861
5 6 60755 61881
6 7 17102 36593
7 8 2683 20220
5 9 378 30908
9 10 20784 26201
9 11 7667 50249
8 12 61164 89813
12 13 1991 91334
13 14 1120 48960
14 15 3307 74478
12 16 58973 77485
15 17 71563 79400
13 18 26561 72750
17 19 ...

output:

1
359165429
340388599
159112969
971579662
964628155
733006594
552742784
11753078
248778357
74621876
545969726
165287702
513750257
753945119
136793674
484041223
413771740
75281701
907086760
917266414
410558233
634762818
807180494
128593490
774012036
313497968
542615885
760781306
609446870
131091714
9...

result:

ok 100000 numbers

Test #30:

score: 0
Accepted
time: 87ms
memory: 33376kb

input:

100000 120000
1 2 19213 51778
2 3 65767 78951
2 4 57318 65064
2 5 69609 80048
2 6 49287 77784
2 7 9156 80807
3 8 7433 22728
2 9 17639 71664
6 10 24524 76835
5 11 51508 91114
7 12 38912 50270
4 13 54764 83998
8 14 52395 65947
6 15 26001 66661
7 16 27650 77345
4 17 4982 65528
7 18 74326 86894
7 19 390...

output:

1
789700007
650381052
884886574
800858964
272653736
886090071
881535875
312480915
864625252
684302480
382978267
265811077
597389079
559804189
619874059
848856281
174413713
19829766
167247455
822286137
912076056
979372880
720053278
633647558
374091352
541544715
401880679
478422373
643610909
335722972...

result:

ok 100000 numbers

Test #31:

score: 0
Accepted
time: 224ms
memory: 37092kb

input:

100000 300000
1 2 96487 96660
1 3 53100 70654
3 4 32849 86185
3 5 87280 88773
2 6 55381 56741
6 7 19920 79540
3 8 15689 17408
6 9 26316 27417
5 10 93291 99784
5 11 77492 80068
9 12 29227 55335
3 13 25505 31444
7 14 10720 71397
4 15 33173 39151
11 16 12873 52174
11 17 15280 57700
10 18 10156 33187
10...

output:

1
619268149
23283986
718156815
656216941
344359101
13931390
136475562
363496523
629864717
2206710
182993944
724489157
711953341
24622606
997537245
507491821
602672063
532279085
359104919
742719367
397555042
356750360
708047299
738052427
248465815
693802382
908181511
962994191
846113550
984393089
213...

result:

ok 100000 numbers

Test #32:

score: 0
Accepted
time: 219ms
memory: 37812kb

input:

100000 300000
1 2 87003 93125
2 3 77861 87154
3 4 2220 97511
3 5 14111 56121
5 6 21632 72223
2 7 27619 60289
3 8 6818 87040
1 9 4746 55070
1 10 40327 41392
5 11 12520 60692
9 12 32108 53702
7 13 63144 84746
10 14 9433 48040
10 15 15606 33848
12 16 14642 18038
8 17 18575 61531
9 18 19209 69501
8 19 5...

output:

1
19552191
864458244
743164657
575883417
822575546
415428445
212328010
504342795
586738667
911163069
431105500
9145464
434652712
356815960
695106908
499554207
43108785
715876789
361540106
922593612
150635319
501672595
110942301
508572554
546281317
31445615
874546818
910478495
165581061
205042918
476...

result:

ok 100000 numbers

Test #33:

score: 0
Accepted
time: 221ms
memory: 38108kb

input:

100000 300000
1 2 13487 24036
1 3 69563 98834
1 4 18163 53872
2 5 8929 74247
2 6 68783 99229
5 7 50699 71053
3 8 30537 66258
5 9 13542 24158
8 10 16652 56783
3 11 47071 65427
4 12 22423 58768
3 13 33885 72606
6 14 17159 79742
11 15 16674 23338
14 16 68520 99866
11 17 88462 94116
14 18 53724 92764
5 ...

output:

1
491929723
978296435
348307082
678907678
240406610
373418011
238074071
356869573
677032660
831517546
335813993
731415523
680512867
358744671
279391160
772697234
687645255
220566626
25713072
281811411
50725540
79849172
632256821
424925304
292394348
427496987
54508115
888445037
616933879
798990434
77...

result:

ok 100000 numbers

Test #34:

score: 0
Accepted
time: 206ms
memory: 36236kb

input:

100000 300000
1 2 17160 72522
2 3 63794 70109
3 4 20028 75506
2 5 11024 30763
4 6 15131 32968
3 7 27866 94913
2 8 4006 10939
2 9 19790 75927
5 10 42657 96045
4 11 12281 60574
2 12 19225 51478
7 13 14198 21662
1 14 20122 58493
7 15 32956 75798
9 16 27967 68543
3 17 14044 88081
4 18 61076 71667
10 19 ...

output:

1
270641743
705141114
586305736
646035654
433219542
267928574
192466843
475876480
107033049
654408955
86243704
256518218
322224055
965429768
775538769
825216784
539167332
427455286
3307893
904316766
591464692
843992758
91091355
665706668
855317337
586802897
768156213
466788694
48847583
662493343
686...

result:

ok 100000 numbers

Test #35:

score: 0
Accepted
time: 200ms
memory: 38616kb

input:

100000 300000
1 2 9555 37522
2 3 61811 99821
3 4 26690 76390
3 5 5841 48889
4 6 64769 92729
6 7 73872 93646
4 8 54437 63446
5 9 10051 50095
9 10 30892 48219
8 11 48720 74313
11 12 41793 48637
7 13 37299 68057
13 14 3266 90432
14 15 40129 83529
14 16 29419 78450
13 17 45012 83931
14 18 94931 95590
14...

output:

1
512583923
228478337
529227780
332861558
726400303
561609911
946358194
298516321
576890064
599441757
616009146
213127511
718606326
874458180
873409497
533805220
103142979
190014648
814885003
841921735
262287270
137381900
5896834
534648841
389747648
449738271
557654107
644981177
445359413
717561470
...

result:

ok 100000 numbers

Test #36:

score: 0
Accepted
time: 201ms
memory: 36496kb

input:

100000 300000
1 2 58507 75551
2 3 74286 93365
3 4 85168 87716
2 5 17730 31180
2 6 58980 80251
4 7 38586 41726
2 8 50134 52856
2 9 28526 37704
3 10 30496 37259
6 11 41447 45933
6 12 33551 93368
3 13 30042 90601
7 14 16239 28467
3 15 35637 65151
9 16 68661 90776
9 17 48843 62879
7 18 81613 89515
5 19 ...

output:

1
735652088
434480971
94149559
228784636
130745254
552464358
105649781
534761779
797595918
275130049
739287866
944386727
612684373
539138663
145584865
647873851
353785053
126431319
758731541
823138967
417131031
41893986
360072944
838206529
147542498
919976782
48545731
823064071
63352311
968069725
58...

result:

ok 100000 numbers

Test #37:

score: 0
Accepted
time: 201ms
memory: 37972kb

input:

100000 300000
1 2 52998 78870
2 3 9413 85966
3 4 33183 36352
3 5 615 39450
2 6 36577 76811
4 7 49351 64806
3 8 47536 58390
4 9 7070 7524
3 10 22605 47760
6 11 9733 27826
3 12 62963 83683
7 13 76437 78460
7 14 23122 85359
7 15 23629 32475
5 16 43489 51652
12 17 21871 41015
12 18 12778 40473
4 19 3977...

output:

1
734273462
823806151
737856899
499818843
669088651
232745811
753044966
745293696
777909031
46159497
743986639
100341615
93002115
495915907
162274820
644419470
295514192
883111292
958180277
617876804
407042865
924168344
345018570
579496278
662643745
662081980
928455106
705235237
935732741
807209546
...

result:

ok 100000 numbers

Test #38:

score: 0
Accepted
time: 2ms
memory: 9636kb

input:

6 8
1 2 1 2
1 3 1 3
3 4 3 4
3 5 3 5
5 6 5 6
6 3 6 13
6 2 6 12
3 6 3 6

output:

1
790276780
332748118
748683265
598946612
748683265

result:

ok 6 numbers

Extra Test:

score: 0
Extra Test Passed