Submission details
Task:Sprinklers
Sender:Vludo
Submission time:2025-03-03 17:51:12 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.01 s1, 5details
#20.01 s1, 3, 5details
#30.01 s1, 5details
#40.01 s1, 5details
#50.01 s1, 3, 5details
#60.01 s1, 3, 5details
#70.01 s1, 5details
#80.01 s1, 3, 5details
#90.01 s2, 5details
#100.01 s2, 5details
#110.01 s2, 5details
#120.01 s2, 5details
#130.01 s2, 3, 5details
#140.01 s2, 3, 5details
#150.01 s2, 5details
#160.01 s2, 5details
#170.01 s2, 5details
#180.01 s2, 5details
#190.01 s2, 5details
#200.04 s2, 4, 5details
#210.01 s2, 4, 5details
#220.01 s2, 5details
#230.01 s2, 5details
#240.01 s3, 5details
#250.01 s3, 5details
#260.01 s3, 5details
#270.01 s3, 5details
#280.01 s3, 5details
#290.01 s3, 5details
#300.01 s3, 5details
#310.01 s3, 5details
#320.01 s3, 5details
#330.01 s3, 5details
#340.01 s3, 5details
#350.01 s3, 5details
#360.01 s3, 4, 5details
#370.01 s3, 4, 5details
#380.01 s3, 5details
#390.01 s3, 5details
#400.01 s3, 5details
#410.01 s3, 5details
#420.01 s4, 5details
#430.01 s4, 5details
#440.01 s4, 5details
#450.01 s4, 5details
#460.01 s4, 5details
#470.01 s4, 5details
#480.01 s4, 5details
#490.01 s4, 5details
#500.01 s4, 5details
#510.01 s4, 5details
#520.01 s1, 3, 4, 5details
#530.01 s3, 4, 5details
#540.01 s4, 5details
#550.01 s4, 5details
#560.01 s4, 5details
#57--4, 5details
#58--4, 5details
#59--4, 5details
#600.03 s4, 5details
#610.03 s4, 5details
#620.01 s4, 5details
#630.01 s4, 5details
#640.01 s4, 5details
#650.01 s4, 5details
#660.01 s4, 5details
#670.01 s4, 5details
#680.01 s4, 5details
#690.03 s4, 5details
#700.02 s4, 5details
#710.02 s4, 5details
#720.01 s5details
#730.01 s5details
#740.01 s5details
#750.01 s3, 5details
#760.01 s5details
#770.01 s5details
#780.01 s5details
#790.01 s5details
#800.01 s5details
#810.01 s5details
#820.01 s5details
#830.01 s4, 5details
#840.01 s5details
#850.01 s5details
#860.01 s5details
#870.01 s5details

Code

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define N ((int)70007)
#define F first
#define S second

int n, k;
vector<pii> v[N];
bool vis[1010][1010];
int result[N];
map<int,int> mem; 

void haku(int as) {
    vis[as][as] = true; 
    queue<pii> q;
    q.push({as, k});

    while (!q.empty()) {
        auto[s, fuel] = q.front();
        q.pop();
        for(pii i : v[s]) if (!vis[as][i.F]) {
            vis[as][i.F] = true;
            if (fuel < i.S) {
                //cout << s << "->" << i.F << ": "<<fuel<<endl; 
                q.push({i.F, k-i.S});
                result[s]+=mem[s+365987*i.F];
            }
            else q.push({i.F, fuel-i.S});
        }
    }
}
int osa2() {
    int s=0, i=1;
    for(;s<n;++s) 
        if (v[s].size()==1) break;
    while (i<=n) {
        int left = i-1;
        int right = n-i;
        result[s] = ((int)(right/k)*left+(int)(left/k)*right);
        if (v[s].size())
            s = ((v[s].size()>1 && v[s][1].F!=s) ? v[s][1].F : v[s][0].F);
        i++;
    }
    for (int i=0;i<n;++i) cout << result[i] << endl;
    return 0;
}
int main() {
    cin >> n >> k;
    int D = 0;
    for (int i=0;i<n-1;++i) {
        int a,b,c; 
        cin >> a >> b >> c;
        v[a].push_back({b,c});
        v[b].push_back({a,c});
        D = max(D, (int)max(v[a].size(), v[b].size()));
    }
    if (D<=2) return osa2(); 
    for (int i=0;i<n;++i) {
        for (pii j : v[i]) {
            int counter = 0;
            queue<pii> q;
            q.push({j.F,i}); 
            while (!q.empty()) {
                counter++;
                auto[s,e] = q.front();
                q.pop();
                for (pii ii : v[s]) if (ii.F!=e) {
                    q.push({ii.F, s});
                }
            }
            mem[i+365987*j.F]=counter;
        }
    }
    for (int i=0;i<n;++i) haku(i);
    for (int i=0;i<n;++i) cout << result[i] << endl;
}

Test details

Test 1

Group: 1, 5

Verdict:

input
1 83222
466934787
466783611 466783616 466783616 ...

correct output
151176
L

user output
0

Test 2

Group: 1, 3, 5

Verdict:

input
1 10
197246686
197246686 197246689 197246697 ...

correct output
25
R

user output
0

Test 3

Group: 1, 5

Verdict:

input
1 100000
509281009
668 9457 15494 31210 31822 450...

correct output
-1

user output
0

Test 4

Group: 1, 5

Verdict:

input
1 100000
624632547
26951 33045 39690 54277 56614 ...

correct output
-1

user output
0

Test 5

Group: 1, 3, 5

Verdict:

input
1 1
756911145
10809834

correct output
746101311
L

user output
0

Test 6

Group: 1, 3, 5

Verdict:

input
1 100
14978712
28845401 29889794 32130273 454...

correct output
983677764
R

user output
0

Test 7

Group: 1, 5

Verdict:

input
1 19433
962956432
34486 78490 104057 107887 1169...

correct output
-1

user output
0

Test 8

Group: 1, 3, 5

Verdict:

input
1 10
24301077
24301052 24301056 24301062 243...

correct output
25
L

user output
0

Test 9

Group: 2, 5

Verdict:

input
999 99900
1502618 1502618 1502618 400193...

correct output
200
LRRLRRLRRLRRLRRLRRLRRLRRLRRLRR...

user output
(empty)

Test 10

Group: 2, 5

Verdict:

input
9942 4334
183568 183568 183568 198355 19...

correct output
798846
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 11

Group: 2, 5

Verdict:

input
99999 100000
26111 26111 26111 65653 65653 ...

correct output
155172
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 12

Group: 2, 5

Verdict:

input
99999 100000
163011 163011 163011 175353 17...

correct output
168354
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 13

Group: 2, 3, 5

Verdict:

input
3 1
633088017 633088017 633088017
885362084

correct output
252274067
RRR

user output
(empty)

Test 14

Group: 2, 3, 5

Verdict:

input
9 9
125394468 125394468 125394468 ...

correct output
187674801
LRRLRRLRR

user output
(empty)

Test 15

Group: 2, 5

Verdict:

input
99999 100000
701173862 701173862 701173862 ...

correct output
701173862
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 16

Group: 2, 5

Verdict:

input
99999 100000
651401018 651401018 651401018 ...

correct output
651401018
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 17

Group: 2, 5

Verdict:

input
99999 100000
140165900 140165900 140165900 ...

correct output
859734108
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 18

Group: 2, 5

Verdict:

input
99999 100
23061 23061 23061 27199 27199 ...

correct output
85916
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 19

Group: 2, 5

Verdict:

input
37845 89714
41654 41654 41654 53633 53633 ...

correct output
429003
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 20

Group: 2, 4, 5

Verdict:

input
99996 66672
3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 ...

correct output
2
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 21

Group: 2, 4, 5

Verdict:

input
99996 66672
13 13 13 24 24 24 28 28 28 35 ...

correct output
8
LRRLRRRRRRRRLRRRRRRRRLRRRRRLRR...

user output
(empty)

Test 22

Group: 2, 5

Verdict:

input
99996 66672
231 231 231 376 376 376 400 40...

correct output
143
LRRRRRRRRRRRLRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 23

Group: 2, 5

Verdict:

input
99996 66672
313 313 313 606 606 606 684 68...

correct output
1012
RRRRRRRRRLRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 24

Group: 3, 5

Verdict:

input
10 500
183182418 212709600 299577790 ...

correct output
2000
LRRRLLLRLR

user output
(empty)

Test 25

Group: 3, 5

Verdict:

input
7 368
97707947 250716976 255404837 2...

correct output
536784
LRRRRLR

user output
(empty)

Test 26

Group: 3, 5

Verdict:

input
10 1000
65702117 395462197 513069493 6...

correct output
327562297
LLRLRRRRRR

user output
(empty)

Test 27

Group: 3, 5

Verdict:

input
10 1000
40305583 103260556 109377950 2...

correct output
195785832
RLRRRRLRRR

user output
(empty)

Test 28

Group: 3, 5

Verdict:

input
9 9
36556452 91308619 95898995 247...

correct output
132459734
RRRRRRLLL

user output
(empty)

Test 29

Group: 3, 5

Verdict:

input
10 1000
241758070 241758290 241758298 ...

correct output
758241215
RLRRRRRRRR

user output
(empty)

Test 30

Group: 3, 5

Verdict:

input
10 1000
179343383 179344207 179345310 ...

correct output
820649504
RLRRRRRRRR

user output
(empty)

Test 31

Group: 3, 5

Verdict:

input
10 1000
988214890 988224447 988224659 ...

correct output
988214890
LLRRRRRRRR

user output
(empty)

Test 32

Group: 3, 5

Verdict:

input
10 100
50880185 191440037 219291907 2...

correct output
286863621
RLRRRRRRRR

user output
(empty)

Test 33

Group: 3, 5

Verdict:

input
10 1000
311646654 338177203 381749285 ...

correct output
309070541
LRLRRRRRRR

user output
(empty)

Test 34

Group: 3, 5

Verdict:

input
10 1000
71693478 348972817 393083371 6...

correct output
276872833
LLLRLRRRRR

user output
(empty)

Test 35

Group: 3, 5

Verdict:

input
8 295
98422253 141167953 316067102 5...

correct output
214200320
RLRRLRRR

user output
(empty)

Test 36

Group: 3, 4, 5

Verdict:

input
10 672
0 0 0 9 10 16 28 33 39 40
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
2
RRRLRRLRRR

user output
0
0
0
0
0
...

Test 37

Group: 3, 4, 5

Verdict:

input
10 672
0 1 4 37 40 64 112 129 142 148
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
8
RRRLRRLLLL

user output
0
0
0
0
0
...

Test 38

Group: 3, 5

Verdict:

input
10 672
22 109 112 667 715 1144 2002 2...

correct output
143
RLRLRRLLRL

user output
0
0
0
0
0
...

Test 39

Group: 3, 5

Verdict:

input
10 672
114 598 799 4722 5060 8096 141...

correct output
1012
RLRLRRLLRL

user output
0
0
0
0
0
...

Test 40

Group: 3, 5

Verdict:

input
2 1000
189057837 676622022
211569 1252126 2510381 2648587...

correct output
809330298
RL

user output
(empty)

Test 41

Group: 3, 5

Verdict:

input
2 1000
543825251 872422478
746973 933128 1390535 2435206 ...

correct output
871675505
RL

user output
(empty)

Test 42

Group: 4, 5

Verdict:

input
10000 100000
36430 83260 143004 617277 6200...

correct output
8
LLLLLLLLRLLLLRRRLLRRLLLLLLLLLL...

user output
(empty)

Test 43

Group: 4, 5

Verdict:

input
100000 100000
15984 32935 37288 51871 75972 ...

correct output
7
RLRRRRRRRRRRRRRRLRRRRLRLRRRRRR...

user output
(empty)

Test 44

Group: 4, 5

Verdict:

input
100000 100000
18784 21819 35288 36764 49875 ...

correct output
8
RRRRLRLLRRRRLLRRRLRRRRRLRLRRRR...

user output
(empty)

Test 45

Group: 4, 5

Verdict:

input
100000 100000
10696 22875 41823 58070 64645 ...

correct output
5
RRRLRLRLRLRRRRRLLRRRRRRRRRLRRL...

user output
(empty)

Test 46

Group: 4, 5

Verdict:

input
100000 100000
17004 23429 52051 69103 97291 ...

correct output
7
RLLLLRRRRRRLRRLRLRRRRLRRLRRLRR...

user output
(empty)

Test 47

Group: 4, 5

Verdict:

input
100000 100000
10000 10293 12721 22625 22627 ...

correct output
8
LLLRRRRRRRRRLRLLLRRLRLRRRLLLRR...

user output
(empty)

Test 48

Group: 4, 5

Verdict:

input
100000 100000
6079 6085 8279 9556 26520 4237...

correct output
8
RRLRLLRLRRRLRRLRRRRLLRLRLRLRLL...

user output
(empty)

Test 49

Group: 4, 5

Verdict:

input
100000 100000
75 24481 38465 38466 38472 727...

correct output
8
RRLRRRRRRRRLRLRRRRLRRRRLRRRLLR...

user output
(empty)

Test 50

Group: 4, 5

Verdict:

input
100000 100000
13888 13894 55906 55907 56392 ...

correct output
8
LRRRLRLLRLLRRLRLLRRRRRRRRLRRRR...

user output
(empty)

Test 51

Group: 4, 5

Verdict:

input
100000 100000
7204 25976 28983 32546 47881 4...

correct output
8
RLRRRRLRLLRLLRRRRLRRLRLLRRRLRR...

user output
(empty)

Test 52

Group: 1, 3, 4, 5

Verdict:

input
1 2
784048766
784048766 784048770

correct output
4
R

user output
0

Test 53

Group: 3, 4, 5

Verdict:

input
9 9
123595330 201675307 201675308 ...

correct output
1
RRRLRRRRR

user output
(empty)

Test 54

Group: 4, 5

Verdict:

input
100000 100
2602 37769 58904 67992 67992 9...

correct output
0
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 55

Group: 4, 5

Verdict:

input
100000 1000
1246 7878 9408 34366 48623 504...

correct output
1
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 56

Group: 4, 5

Verdict:

input
100000 1000
40857 50756 54202 59438 60236 ...

correct output
8
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 57

Group: 4, 5

Verdict:

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
8
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 58

Group: 4, 5

Verdict:

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
6
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 59

Group: 4, 5

Verdict:

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
4
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 60

Group: 4, 5

Verdict:

input
100000 100000
2 2 3 3 4 4 5 5 6 7 8 11 11 12...

correct output
5
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 61

Group: 4, 5

Verdict:

input
100000 100000
0 0 0 0 1 2 7 7 7 8 8 10 12 13...

correct output
7
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Test 62

Group: 4, 5

Verdict:

input
100000 100000
0 3 50 52 53 70 82 107 107 126...

correct output
8
RRRRRRRRRRRRRRRRRRRRRRRRRRLLRR...

user output
(empty)

Test 63

Group: 4, 5

Verdict:

input
100000 100000
18 24 26 46 55 57 69 96 106 10...

correct output
8
RRRLRRLRRRRRRRLRRRRRRRRRLRRRRL...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Test 64

Group: 4, 5

Verdict:

input
100000 100000
206 212 247 269 334 411 593 60...

correct output
8
RRRLRRRRRLLRRLLLRRLRRRRRRRRRRR...

user output
(empty)

Test 65

Group: 4, 5

Verdict:

input
100000 100000
92 143 202 204 264 308 345 371...

correct output
8
RLRRRLRRLRRRLRRRRLRRRRLRRRRRRL...

user output
(empty)

Test 66

Group: 4, 5

Verdict:

input
80154 9438
42273 45355 54187 63725 91361 ...

correct output
2
RRRLLRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 67

Group: 4, 5

Verdict:

input
38898 29607
40780 40781 70137 101166 11258...

correct output
8
RRLLLRLRRRRRLRRLLLRRRRRRRRRRLR...

user output
(empty)

Test 68

Group: 4, 5

Verdict:

input
80060 99998
30 32 51 53 65 67 76 78 94 96 ...

correct output
4
LRLRLRRLRLRLRLRLRLLRLRRLLRRLRL...

user output
(empty)

Test 69

Group: 4, 5

Verdict:

input
100000 66672
0 2 2 2 2 2 3 3 3 3 4 4 4 5 5 ...

correct output
2
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Test 70

Group: 4, 5

Verdict:

input
100000 66672
0 1 2 2 3 4 5 7 10 11 12 12 14...

correct output
4
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 71

Group: 4, 5

Verdict:

input
100000 66672
2 4 5 5 9 10 24 28 38 39 46 49...

correct output
8
RRRRRRRRRRRRRRRLRRRRRRRRRRRRRR...

user output
(empty)

Test 72

Group: 5

Verdict:

input
2000 100000
194733 864089 2391039 2487806 ...

correct output
100
LLLLLRLLLRLLRRRRLRLLRLLLLLLLRL...

user output
(empty)

Test 73

Group: 5

Verdict:

input
100000 100000
33199 36596 45922 50591 57613 ...

correct output
59591
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 74

Group: 5

Verdict:

input
100000 100000
7413 8312 13159 27037 36840 42...

correct output
54908
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 75

Group: 3, 5

Verdict:

input
9 9
139383229 193752719 468046357 ...

correct output
126661501
RLLLRRRRR

user output
(empty)

Test 76

Group: 5

Verdict:

input
100000 100000
935103974 935103974 935103974 ...

correct output
935103974
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 77

Group: 5

Verdict:

input
100000 100000
352052926 352052926 352052926 ...

correct output
647937074
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 78

Group: 5

Verdict:

input
100000 100000
933066547 933066548 933066548 ...

correct output
933066547
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 79

Group: 5

Verdict:

input
100000 100
10423 15052 26137 27860 41395 ...

correct output
26084
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 80

Group: 5

Verdict:

input
100000 1000
7482 21863 23121 63084 95374 1...

correct output
40860
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 81

Group: 5

Verdict:

input
100000 1000
581 6209 12415 12626 18099 605...

correct output
37200
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 82

Group: 5

Verdict:

input
5056 54016
13380 123614 168690 320466 615...

correct output
1225649
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 83

Group: 4, 5

Verdict:

input
79988 100000
28 30 46 48 70 72 90 92 106 10...

correct output
4
RLLRRLRLLRLRLRRLLRRLRLRLRLLRRL...

user output
(empty)

Test 84

Group: 5

Verdict:

input
100000 66672
0 4 133 181 182 183 186 250 30...

correct output
143
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Test 85

Group: 5

Verdict:

input
100000 66672
23 162 696 1403 1474 1507 1894...

correct output
1012
LRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Test 86

Group: 5

Verdict:

input
2 100000
492620862 873092338
19913 31316 32969 33962 43720 ...

correct output
873072425
RL

user output
(empty)

Test 87

Group: 5

Verdict:

input
2 100000
351394362 401836177
16699 17194 20928 21271 22083 ...

correct output
648600120
RL

user output
(empty)