QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282090#7871. 命运hos_lyric#100 ✓147ms24216kbC++147.1kb2023-12-11 13:11:432024-07-04 03:12:17

Judging History

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

  • [2024-07-04 03:12:17]
  • 评测
  • 测评结果:100
  • 用时:147ms
  • 内存:24216kb
  • [2023-12-11 13:11:43]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// Link-Cut Tree, with subtree information
//   solid path as BST; left: root side
//   Modify update() for other data.
struct Tree {
  Tree *l, *r, *p;
  // int sz;
  int id;
  int val, sum;
  int light;
  explicit Tree(int id_ = -1, int val_ = 0) : id(id_), val(val_), sum(val_) {
  // explicit Tree(int id_ = -1) : id(id_) {
    l = r = p = nullptr;
    // sz = 1;
    light = 0;
  }
  void update() {
    // sz = (l ? l->sz : 0) + 1 + (r ? r->sz : 0);
    // sz = (l ? l->sz : 0) + 1 + (r ? r->sz : 0) + light;
    sum = (l ? l->sum : 0) + val + (r ? r->sum : 0) + light;
  }
  bool isRoot() const {
    return (!p || (p->l != this && p->r != this));
  }
  void rotate() {
         if (p->l == this) { if (r) { r->p = p; } p->l = r; r = p; }
    else if (p->r == this) { if (l) { l->p = p; } p->r = l; l = p; }
    Tree *pp = p->p;
    if (pp) {
           if (pp->l == p) pp->l = this;
      else if (pp->r == p) pp->r = this;
    }
    p->update(); p->p = this; p = pp;
  }
  void splay() {
    for (; !isRoot(); rotate()) {
      if (!p->isRoot()) ((p->l == this) == (p->p->l == p)) ? p->rotate() : rotate();
    }
    update();
  }

  // Makes the path from v to the root solid
  // Returns the node where it entered the last solid path
  Tree *expose() {
    Tree *u = this, *v = nullptr;
    // for (; u; u = u->p) { u->splay(); u->r = v; u->update(); v = u; }
    for (; u; u = u->p) {
      u->splay();
      if (u->r) u->light += u->r->sum;
      u->r = v;
      if (u->r) u->light -= u->r->sum;
      u->update();
      v = u;
    }
    splay();
    return v;
  }

  // parent of this := u
  void link(Tree *u) {
    expose(); u->expose(); p = u; u->r = this; u->update();
  }

  // parent of this := null
  void cut() {
    expose(); l->p = nullptr; l = nullptr; update();
  }

  // the root of the tree this belongs
  Tree *root() {
    expose();
    for (Tree *u = this; ; u = u->l) if (!u->l) { u->splay(); return u; }
  }

  // LCA of this and u
  //   Assumes this->root == u->root
  Tree *lca(Tree *u) {
    expose(); return u->expose();
  }
};

////////////////////////////////////////////////////////////////////////////////


vector<int> uf;
int root(int u) {
  return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
  u = root(u);
  v = root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}


int N, M, K, S;
vector<pair<int, pair<int, int>>> E;
vector<int> A, B, C;

vector<vector<int>> G;
vector<int> vis;
void dfs(int u, int p) {
  vis[u] = 1;
  for (const int i : G[u]) {
    const int v = A[i] ^ B[i] ^ u;
    if (p != v) {
      if (B[i] == u) {
        swap(A[i], B[i]);
      }
// cerr<<A[i]<<" <- "<<B[i]<<endl;
      dfs(v, u);
    }
  }
}

vector<Tree> nodes;
int degS, numComps;

int main() {
  for (; ~scanf("%d%d%d%d", &N, &M, &K, &S); ) {
    --S;
    E.resize(M);
    for (int i = 0; i < M; ++i) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      --a;
      --b;
      if (b == S) {
        swap(a, b);
      }
      E[i] = make_pair(c, make_pair(a, b));
    }
    sort(E.begin(), E.end());
    A.resize(M);
    B.resize(M);
    C.resize(M);
    for (int i = 0; i < M; ++i) {
      A[i] = E[i].second.first;
      B[i] = E[i].second.second;
      C[i] = E[i].first;
    }
// cerr<<"E = "<<E<<endl;
    
    /*
      - no multi-edge from S
      - not in MST other than S
    */
    vector<int> ban(M, 0);
    vector<int> used(N, 0);
    {
      for (int i = 0; i < M; ++i) if (A[i] == S) {
        if (used[B[i]]) ban[i] = 1;
        used[B[i]] = 1;
      }
    }
    {
      uf.assign(N, -1);
      for (int i = 0; i < M; ++i) if (A[i] != S) {
        if (!connect(A[i], B[i])) {
          ban[i] = 1;
        }
      }
    }
    
    vector<int> on(M);
    for (int i = 0; i < M; ++i) {
      on[i] = ban[i] ^ 1;
    }
    
    nodes.resize(N);
    for (int u = 0; u < N; ++u) {
      nodes[u] = Tree(u, used[u]);
    }
    
    G.assign(N, {});
    for (int i = 0; i < M; ++i) if (on[i]) if (A[i] != S) {
      G[A[i]].push_back(i);
      G[B[i]].push_back(i);
    }
    vis.assign(N, 0);
    vector<int> rs;
    for (int u = 0; u < N; ++u) if (u != S) if (!vis[u]) {
      rs.push_back(u);
      dfs(u, -1);
    }
    for (int i = 0; i < M; ++i) if (on[i]) if (A[i] != S) {
      nodes[B[i]].link(&nodes[A[i]]);
    }
    
    bool ok = true;
    degS = 0;
    for (int i = 0; i < M; ++i) if (on[i]) if (A[i] == S) {
      ++degS;
    }
    ok = ok && (degS >= K);
    numComps = rs.size();
    for (const int r : rs) {
      nodes[r].expose();
// cerr<<"r = "<<r<<": "<<nodes[r].sum<<endl;
      ok = ok && (nodes[r].sum >= 1);
    }
    ok = ok && (numComps <= K);
cerr<<"degS = "<<degS<<", numComps = "<<numComps<<endl;
    
    if (ok) {
      for (int i = M; --i >= 0; ) if (!ban[i]) {
        auto checkOff = [&]() -> bool {
          if (A[i] == S) {
            if (degS - 1 >= K && nodes[B[i]].root()->sum - 1 >= 1) {
              --degS;
              nodes[B[i]].expose();
              nodes[B[i]].val -= 1;
              nodes[B[i]].update();
              return true;
            } else {
              return false;
            }
          } else {
            ++numComps;
            nodes[B[i]].cut();
            if (numComps <= K && nodes[A[i]].root()->sum >= 1 && nodes[B[i]].root()->sum >= 1) {
              return true;
            } else {
              --numComps;
              nodes[B[i]].link(&nodes[A[i]]);
              return false;
            }
          }
        };
        if (checkOff()) {
          on[i] = 0;
        }
      }
      Int ans = 0;
      for (int i = 0; i < M; ++i) if (on[i]) {
        ans += C[i];
      }
      printf("%lld\n", ans);
    } else {
      puts("nonnondayo");
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 27ms
memory: 10276kb

input:

49277 49276 1 49277
1 2 2000
2 3 3000
2 4 4000
3 5 5000
3 6 6000
4 7 7000
1 8 8000
7 9 9000
1 10 10000
5 11 11000
4 12 12000
3 13 13000
13 14 14000
1 15 15000
7 16 16000
11 17 17000
2 18 18000
10 19 19000
6 20 20000
4 21 21000
17 22 22000
1 23 23000
14 24 24000
4 25 25000
16 26 26000
15 27 27000
9 2...

output:

1214136002000

result:

ok single line: '1214136002000'

Test #2:

score: 0
Accepted
time: 25ms
memory: 10064kb

input:

49324 49323 1 49324
1 2 2
2 3 3
2 4 4
3 5 5
4 6 6
6 7 7
2 8 8
2 9 9
4 10 10
6 11 11
9 12 12
4 13 13
8 14 14
8 15 15
7 16 16
11 17 17
15 18 18
2 19 19
10 20 20
19 21 21
14 22 22
16 23 23
20 24 24
23 25 25
3 26 26
2 27 27
8 28 28
11 29 29
20 30 30
15 31 31
16 32 32
19 33 33
29 34 34
5 35 35
21 36 36
1...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #3:

score: 0
Accepted
time: 20ms
memory: 10036kb

input:

49423 49422 1 1
1 2 2
2 3 3
1 4 4
3 5 5
2 6 6
1 7 7
1 8 8
7 9 9
3 10 10
3 11 11
5 12 12
3 13 13
9 14 14
10 15 15
13 16 16
5 17 17
9 18 18
12 19 19
17 20 20
4 21 21
5 22 22
12 23 23
21 24 24
21 25 25
11 26 26
17 27 27
21 28 28
18 29 29
17 30 30
2 31 31
21 32 32
28 33 33
17 34 34
31 35 35
11 36 36
8 3...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #4:

score: 0
Accepted
time: 27ms
memory: 10088kb

input:

49501 49500 49501 49501
1 2 2
1 3 3
3 4 4
2 5 5
5 6 6
1 7 7
6 8 8
5 9 9
6 10 10
5 11 11
2 12 12
12 13 13
13 14 14
8 15 15
13 16 16
5 17 17
9 18 18
9 19 19
9 20 20
14 21 21
18 22 22
16 23 23
7 24 24
1 25 25
7 26 26
1 27 27
15 28 28
22 29 29
20 30 30
12 31 31
4 32 32
16 33 33
22 34 34
11 35 35
27 36 3...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Subtask #2:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 0ms
memory: 3704kb

input:

21 20 2 21
1 2 18581
1 3 9620
2 4 4362
1 5 7702
5 6 17435
4 7 11679
3 8 14832
1 9 15073
2 10 6595
5 11 19676
11 12 16943
12 13 5268
5 14 20262
8 15 8192
7 16 12340
7 17 1437
7 18 3064
2 19 10437
12 20 2882
19 21 13483

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #6:

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

input:

10 20 4 3
1 2 18247
2 3 9041
2 4 4031
2 5 7363
3 6 17172
1 7 11014
6 8 14781
8 9 15347
8 10 6598
5 9 19331
3 10 16523
10 6 5732
2 3 20357
6 9 8827
10 3 12864
6 3 1551
5 6 3932
3 1 10223
9 3 2296
8 5 13620

output:

54418

result:

ok single line: '54418'

Test #7:

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

input:

10 20 6 10
1 2 18401
2 3 9843
3 4 4219
4 5 7552
4 6 17751
4 7 11318
5 8 14774
8 9 15541
5 10 6928
6 10 19860
10 5 16699
5 8 5937
5 2 20611
1 8 8077
10 1 12386
9 4 1663
9 10 3910
1 9 10401
7 10 2383
2 9 13681

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #8:

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

input:

10 20 1 10
1 2 18853
2 3 9034
3 4 4069
3 5 7743
3 6 17122
6 7 11715
2 8 14814
1 9 15011
7 10 6248
6 8 19400
7 3 16354
6 8 5249
7 8 20701
5 10 8079
10 5 12570
7 10 1006
8 3 3814
5 10 10753
5 9 2310
8 6 13123

output:

59951

result:

ok single line: '59951'

Test #9:

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

input:

10 11 3 1
1 2 9407
1 3 7005
1 4 5453
1 5 4585
1 6 8278
1 7 6332
1 8 1415
1 9 3809
1 10 10519
2 6 2507
10 6 11580

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Subtask #3:

score: 15
Accepted

Dependency #2:

100%
Accepted

Test #10:

score: 15
Accepted
time: 1ms
memory: 3976kb

input:

1000 3000 100 10
1 2 2270918
1 3 871400
2 4 1242131
3 5 2307909
5 6 1391239
3 7 1431327
7 8 2501929
5 9 2377716
8 10 612146
5 11 991199
11 12 1810465
10 13 1094558
10 14 2605381
8 15 872336
10 16 2092297
5 17 619719
14 18 1161002
5 19 1828768
10 20 837691
2 21 1787203
3 22 396276
21 23 1371664
16 24...

output:

645739778

result:

ok single line: '645739778'

Test #11:

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

input:

999 3000 200 20
1 2 2801619
1 3 1075541
2 4 1533685
3 5 2847120
2 6 1716689
6 7 1766365
5 8 3087429
4 9 2933519
1 10 755477
4 11 1223969
11 12 2233807
5 13 1350595
12 14 3215789
12 15 1076145
12 16 2581528
1 17 764941
5 18 1433263
12 19 2256409
3 20 1033257
20 21 2205421
11 22 489324
22 23 1692840
2...

output:

833854746

result:

ok single line: '833854746'

Test #12:

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

input:

999 3000 300 20
1 2 9811687
2 3 3764791
2 4 5370818
3 5 9972642
3 6 6014501
1 7 6187455
6 8 10808965
2 9 10272798
9 10 2646297
1 11 4285235
1 12 7821976
2 13 4727798
13 14 11258977
11 15 3768331
1 16 9040806
16 17 2678040
6 18 5018287
5 19 7901529
14 20 3617199
20 21 7721668
20 22 1713474
21 23 5927...

output:

3113047747

result:

ok single line: '3113047747'

Test #13:

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

input:

999 3000 10 20
1 2 9812725
2 3 3765199
3 4 5368570
1 5 9970744
2 6 6012531
5 7 6184148
6 8 10808057
6 9 10272720
4 10 2647288
4 11 4284300
5 12 7824819
4 13 4731348
6 14 11256433
1 15 3771674
6 16 9042651
16 17 2677352
2 18 5019297
2 19 7900432
9 20 3619670
9 21 7725236
20 22 1713962
20 23 5927083
2...

output:

2976768482

result:

ok single line: '2976768482'

Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #14:

score: 20
Accepted
time: 23ms
memory: 10568kb

input:

49997 54855 3516 1
3 2 123052288
4 2 96660489
5 4 21916339
6 4 110026562
7 2 37432698
8 4 38560777
9 5 83209343
10 9 80352789
11 2 88956732
12 7 65449905
13 2 38239108
14 5 90154247
15 4 30810782
16 13 96492679
17 14 112886179
18 9 87190321
19 5 91181643
20 3 107304129
21 15 101439791
22 19 12060197...

output:

2688197428747

result:

ok single line: '2688197428747'

Test #15:

score: 0
Accepted
time: 26ms
memory: 10276kb

input:

49997 51737 2558 1
3 2 123053094
4 2 96661142
5 4 21916374
6 3 110026590
7 3 37432598
8 5 38561207
9 3 83209496
10 6 80352500
11 10 88956702
12 8 65450072
13 7 38238198
14 6 90153662
1 2 30811464
16 15 96493667
17 15 112885786
18 16 87189617
19 16 91182345
20 19 107304693
21 16 101440408
22 19 12060...

output:

2837250649688

result:

ok single line: '2837250649688'

Test #16:

score: 0
Accepted
time: 23ms
memory: 10100kb

input:

49991 50261 391 1
3 2 123052091
4 2 96661422
5 4 21916293
6 3 110026296
7 2 37432814
8 6 38560644
9 5 83209409
10 8 80352817
11 5 88956822
12 2 65449972
13 9 38239183
14 12 90154124
15 6 30811280
16 10 96493604
17 15 112886136
18 2 87190273
19 15 91182250
20 8 107304418
21 5 101440651
22 8 120601454...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #17:

score: 0
Accepted
time: 29ms
memory: 10300kb

input:

49996 50165 184 1
3 2 123052595
4 3 96661399
5 2 21916499
6 3 110026337
7 6 37432710
8 2 38560107
9 8 83209370
10 8 80352229
11 2 88957425
12 7 65449321
13 5 38238243
14 5 90153912
15 11 30810953
16 3 96492912
17 13 112885611
18 15 87190336
19 9 91182003
20 2 107304872
21 6 101440738
22 13 120601711...

output:

2902613721568

result:

ok single line: '2902613721568'

Test #18:

score: 0
Accepted
time: 22ms
memory: 10116kb

input:

50000 50178 299 1
3 2 123053073
4 2 96660633
5 3 21916772
6 5 110026921
7 2 37432864
8 4 38561246
9 3 83208661
10 9 80352023
11 5 88956707
12 4 65449462
13 11 38238637
14 9 90154366
15 11 30811612
16 3 96492654
17 2 112885858
18 12 87189668
19 9 91182185
20 2 107304880
21 14 101440435
22 20 12060169...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #19:

score: 0
Accepted
time: 33ms
memory: 10344kb

input:

49995 50087 119 1
3 2 123052834
4 2 96661264
5 2 21915970
6 2 110026190
7 6 37432674
8 5 38560833
9 4 83209622
10 3 80352174
11 7 88957586
12 11 65449265
13 8 38238650
14 13 90154332
15 6 30811223
16 3 96493604
17 8 112885782
18 10 87190407
19 18 91182347
20 2 107304278
21 7 101440830
22 5 120602339...

output:

2907329109512

result:

ok single line: '2907329109512'

Test #20:

score: 0
Accepted
time: 25ms
memory: 7364kb

input:

9991 99999 500 1
1 2 96661103
1 3 21915978
1 4 110026526
1 5 37432238
1 6 38560460
1 7 83209113
1 8 80353115
1 9 88956996
1 10 65449536
1 11 38238621
1 12 90153747
1 13 30810623
1 14 96492948
1 15 112885374
1 16 87190491
1 17 91181949
1 18 107304334
1 19 101440272
1 20 120601968
1 21 122198044
1 22 ...

output:

112457070668

result:

ok single line: '112457070668'

Subtask #5:

score: 10
Accepted

Test #21:

score: 10
Accepted
time: 28ms
memory: 7376kb

input:

9992 99999 500 1
1 2 96661121
1 3 21915940
1 4 110026320
1 5 37433129
1 6 38560320
1 7 83209024
1 8 80352054
1 9 88957672
1 10 65449874
1 11 38239186
1 12 90153728
1 13 30810974
1 14 96493404
1 15 112886259
1 16 87190053
1 17 91182163
1 18 107303768
1 19 101439823
1 20 120601875
1 21 122197599
1 22 ...

output:

112890891818

result:

ok single line: '112890891818'

Test #22:

score: 0
Accepted
time: 28ms
memory: 7348kb

input:

9992 99999 1 1
1 2 96660674
2 3 21916518
2 4 110026286
2 5 37432719
4 6 38560294
5 7 83209368
7 8 80352797
2 9 88957012
6 10 65449023
8 11 38237968
3 12 90153572
12 13 30810767
12 14 96493398
9 15 112886094
8 16 87190517
2 17 91182246
5 18 107304167
15 19 101440398
16 20 120601474
13 21 122197537
21...

output:

74448057849

result:

ok single line: '74448057849'

Test #23:

score: 0
Accepted
time: 24ms
memory: 7456kb

input:

9996 99999 2000 1
1 2 96660545
1 3 21916931
1 4 110026628
1 5 37432991
1 6 38561067
1 7 83208951
1 8 80351952
1 9 88957054
1 10 65449457
1 11 38238861
1 12 90154656
1 13 30811324
1 14 96493311
1 15 112885579
1 16 87189959
1 17 91182035
1 18 107304613
1 19 101440492
1 20 120602368
1 21 122197999
1 22...

output:

222817867069

result:

ok single line: '222817867069'

Test #24:

score: 0
Accepted
time: 24ms
memory: 7512kb

input:

9998 99999 6000 1
1 2 96661358
1 3 21916728
1 4 110026601
1 5 37432478
1 6 38560240
1 7 83209841
1 8 80352730
1 9 88957089
1 10 65450089
1 11 38238321
1 12 90153969
1 13 30810766
1 14 96493287
1 15 112885621
1 16 87190068
1 17 91181672
1 18 107303705
1 19 101440812
1 20 120601672
1 21 122197495
1 22...

output:

514650883971

result:

ok single line: '514650883971'

Test #25:

score: 0
Accepted
time: 22ms
memory: 7320kb

input:

9995 99999 8000 1
1 2 96661390
1 3 21916323
1 4 110026027
1 5 37433293
1 6 38560397
1 7 83209785
1 8 80352815
1 9 88957405
1 10 65449996
1 11 38238934
1 12 90153822
1 13 30811526
1 14 96493201
1 15 112885855
1 16 87190720
1 17 91181544
1 18 107304307
1 19 101440244
1 20 120601746
1 21 122196886
1 22...

output:

nonnondayo

result:

ok single line: 'nonnondayo'

Test #26:

score: 0
Accepted
time: 29ms
memory: 7572kb

input:

9999 99999 20 20
1 2 338468867
2 3 76745032
1 4 385269279
4 5 131075646
4 6 135023312
1 7 291366571
1 8 281365164
8 9 311495712
1 10 229179809
1 11 133897410
3 12 315685852
8 13 107887724
7 14 337881155
9 15 395284833
13 16 305307019
11 17 319285082
6 18 375738280
12 19 355203621
18 20 422302252
13 ...

output:

261371897445

result:

ok single line: '261371897445'

Subtask #6:

score: 20
Accepted

Dependency #3:

100%
Accepted

Test #27:

score: 20
Accepted
time: 25ms
memory: 7388kb

input:

9999 99999 1 20
1 2 338469852
2 3 76743614
3 4 385273039
2 5 131073403
3 6 135023236
6 7 291367753
5 8 281362462
6 9 311495139
6 10 229178582
5 11 133894978
3 12 315685120
10 13 107890835
9 14 337882826
2 15 395283746
7 16 305305887
8 17 319285996
3 18 375737069
16 19 355206723
7 20 422300256
17 21 ...

output:

260937970515

result:

ok single line: '260937970515'

Test #28:

score: 0
Accepted
time: 29ms
memory: 7416kb

input:

9999 99999 2000 20
1 2 338469082
2 3 76741787
1 4 385271488
3 5 131074086
5 6 135026340
5 7 291367570
6 8 281364651
4 9 311496295
4 10 229181495
6 11 133894975
11 12 315685240
5 13 107888207
13 14 337883685
2 15 395284334
11 16 305305912
1 17 319284711
7 18 375740311
2 19 355204904
1 20 422301708
19...

output:

701242141033

result:

ok single line: '701242141033'

Test #29:

score: 0
Accepted
time: 29ms
memory: 7580kb

input:

9999 99999 3 20
1 2 338468888
1 3 76742585
3 4 385269457
1 5 131074295
1 6 135024783
2 7 291367469
4 8 281363696
7 9 311494641
3 10 229179870
10 11 133896196
9 12 315684185
1 13 107888713
1 14 337881888
9 15 395284888
12 16 305307389
15 17 319283019
7 18 375737253
11 19 355204124
8 20 422302728
16 2...

output:

259534141883

result:

ok single line: '259534141883'

Test #30:

score: 0
Accepted
time: 136ms
memory: 24176kb

input:

50000 500000 3 20
1 2 610924644
2 3 624918156
3 4 507006330
4 5 627782983
2 6 611734773
2 7 641063812
6 8 488761318
1 9 657777696
4 10 655598979
1 11 535852783
3 12 631672545
5 13 628709587
2 14 651271751
14 15 651366378
15 16 590907002
11 17 659314718
2 18 644602197
17 19 557850275
9 20 646422134
1...

output:

1992242416798

result:

ok single line: '1992242416798'

Subtask #7:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #31:

score: 20
Accepted
time: 147ms
memory: 24136kb

input:

50000 500000 3 20
1 2 610924797
1 3 624918486
1 4 507005808
2 5 627783449
2 6 611734590
2 7 641064025
1 8 488761483
6 9 657778374
2 10 655598554
3 11 535852516
9 12 631673087
12 13 628709519
3 14 651271565
9 15 651365347
4 16 590906185
15 17 659314029
6 18 644602657
11 19 557849977
16 20 646422386
6...

output:

1989623923356

result:

ok single line: '1989623923356'

Test #32:

score: 0
Accepted
time: 144ms
memory: 24092kb

input:

50000 500000 10000 20
1 2 610925163
2 3 624917950
3 4 507005433
4 5 627783914
5 6 611734910
6 7 641063127
1 8 488761152
4 9 657777947
1 10 655598256
10 11 535851920
6 12 631672121
5 13 628709351
5 14 651272607
3 15 651365561
14 16 590906795
12 17 659314154
11 18 644602852
2 19 557849233
6 20 6464225...

output:

7197953517967

result:

ok single line: '7197953517967'

Test #33:

score: 0
Accepted
time: 140ms
memory: 24216kb

input:

50000 500000 100 20
1 2 610924315
2 3 624918585
1 4 507006003
4 5 627783847
5 6 611734900
5 7 641063922
2 8 488762001
7 9 657777475
6 10 655597962
5 11 535852755
1 12 631671853
6 13 628709437
7 14 651272258
13 15 651365581
8 16 590906200
14 17 659314196
11 18 644601942
13 19 557849603
18 20 64642340...

output:

2031133413427

result:

ok single line: '2031133413427'

Extra Test:

score: 0
Extra Test Passed