CSES - Datatähti 2020 loppu - Results
Submission details
Task:Kierrokset
Sender:Samu Huovinen
Submission time:2020-02-09 16:13:59 +0200
Language:CPython3
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
Test results
testverdicttimegroup
#10.02 s1, 2, 4details
#20.02 s1, 4details
#30.02 s1, 4details
#40.02 s1, 4details
#50.02 s2, 4details
#60.02 s4details
#70.02 s4details
#80.02 s4details
#90.02 s2, 4details
#100.02 s4details
#110.02 s4details
#120.02 s4details
#130.03 s2, 4details
#140.03 s4details
#150.03 s4details
#160.03 s4details
#170.04 s2, 4details
#180.04 s4details
#190.05 s4details
#200.04 s4details
#210.11 s2, 4details
#220.16 s4details
#230.15 s4details
#240.14 s4details
#250.49 s2, 4details
#260.86 s4details
#270.79 s4details
#280.90 s4details
#29ACCEPTED0.02 s1, 2, 3, 4details
#30ACCEPTED0.02 s1, 2, 3, 4details
#31ACCEPTED0.02 s1, 2, 3, 4details
#32ACCEPTED0.02 s1, 2, 4details
#330.02 s1, 2, 3, 4details
#34ACCEPTED0.02 s1, 2, 4details
#35ACCEPTED0.02 s1, 2, 4details
#360.02 s1, 3, 4details
#370.02 s1, 4details
#380.02 s1, 4details
#390.02 s1, 4details
#400.02 s1, 4details
#410.02 s1, 4details
#420.02 s1, 4details
#430.02 s1, 4details
#440.02 s1, 4details
#450.02 s1, 4details
#46ACCEPTED0.02 s1, 2, 4details
#47ACCEPTED0.02 s1, 2, 3, 4details
#48ACCEPTED0.02 s1, 2, 3, 4details
#490.02 s1, 2, 4details
#500.02 s1, 4details
#510.64 s2, 4details
#52ACCEPTED0.63 s2, 3, 4details
#53ACCEPTED0.63 s2, 3, 4details
#540.63 s2, 3, 4details
#550.64 s2, 4details
#560.65 s2, 4details
#570.63 s2, 4details
#580.63 s2, 4details
#590.64 s2, 4details
#600.64 s2, 4details
#610.63 s2, 4details
#620.65 s2, 4details
#63--4details
#64--4details
#65--4details
#66--4details
#67--4details
#68--4details
#69--4details
#70--4details
#71--4details
#72--4details
#73--3, 4details
#74--3, 4details
#75--3, 4details
#76--3, 4details
#77--3, 4details
#78--3, 4details
#79--3, 4details
#800.99 s3, 4details
#811.00 s3, 4details
#82--3, 4details
#830.74 s2, 4details
#840.71 s2, 4details
#85ACCEPTED0.02 s1, 2, 4details
#86ACCEPTED0.02 s1, 2, 4details

Code

n,x,y = map(int,input().split())

v=[[]]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    v[a]=v[a]+[b]
    v[b]=v[b]+[a]

def haku(pos, vis, d):
    if pos==y:
        global r
        r=vis
        return d
    d+=1
    vis.add(pos)
    for i in v[pos]:
        if i not in vis:
            a=haku(i,vis,d)
            if a!=-1:
                return a
    return -1


d=haku(x,set(),0)
last=x
if len(v[x])==2:
    if v[x][0] in r:
        o=v[x][1]
        b=0
        while len(v[o])==2:
            b+=1
            if v[o][0]==last:
                last=o
                o=v[o][1]
            else:
                last=o
                o=v[o][0]
            
    else:
        b=0
        o=v[x][0]
        while len(o)==2:
            b+=1
            if v[o][0]==last:
                last=o
                o=v[o][1]
            else:
                last=o
                o=v[o][0]

else:
    b=1

print(b*(n-d-b+1))

Test details

Test 1

Group: 1, 2, 4

Verdict:

input
10 5 6
1 2
2 3
3 4
4 5
...

correct output
25

user output
24

Test 2

Group: 1, 4

Verdict:

input
10 8 1
10 7
7 3
8 7
10 9
...

correct output
36

user output
7

Test 3

Group: 1, 4

Verdict:

input
10 10 5
1 6
2 6
2 4
7 2
...

correct output
36

user output
0

Test 4

Group: 1, 4

Verdict:

input
10 7 9
9 6
9 1
1 8
9 2
...

correct output
48

user output
0

Test 5

Group: 2, 4

Verdict:

input
50 46 14
1 2
2 3
3 4
4 5
...

correct output
70

user output
48

Test 6

Group: 4

Verdict:

input
50 49 14
27 13
27 50
5 27
30 5
...

correct output
535291010

user output
0

Test 7

Group: 4

Verdict:

input
50 46 18
24 45
3 24
24 25
32 45
...

correct output
250065865

user output
45

Test 8

Group: 4

Verdict:

input
50 39 9
4 50
5 50
4 28
17 4
...

correct output
145500013

user output
44

Test 9

Group: 2, 4

Verdict:

input
250 166 226
1 2
2 3
3 4
4 5
...

correct output
4150

user output
8964

Test 10

Group: 4

Verdict:

input
250 104 224
118 137
189 118
127 189
132 189
...

correct output
230001327

user output
243

Test 11

Group: 4

Verdict:

input
250 20 113
100 108
220 108
220 228
62 108
...

correct output
734434924

user output
239

Test 12

Group: 4

Verdict:

input
250 116 21
221 16
221 223
22 16
16 79
...

correct output
273467702

user output
239

Test 13

Group: 2, 4

Verdict:

input
1250 556 801
1 2
2 3
3 4
4 5
...

correct output
250200

user output
216909

Test 14

Group: 4

Verdict:

input
1250 1115 100
952 651
952 289
166 952
166 871
...

correct output
600544658

user output
1237

Test 15

Group: 4

Verdict:

input
1250 657 79
13 420
13 346
13 287
1210 420
...

correct output
813695503

user output
1247

Test 16

Group: 4

Verdict:

input
1250 214 271
522 351
140 351
805 351
522 431
...

correct output
212897427

user output
1244

Test 17

Group: 2, 4

Verdict:

input
6250 4685 392
1 2
2 3
3 4
4 5
...

correct output
613872

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 18

Group: 4

Verdict:

input
6250 5270 5866
5282 4610
5282 1160
4610 1967
2502 5282
...

correct output
423709118

user output
6235

Test 19

Group: 4

Verdict:

input
6250 6162 514
4663 2181
6136 2181
6136 3161
3161 2803
...

correct output
949879698

user output
6235

Test 20

Group: 4

Verdict:

input
6250 1522 4950
1937 2721
4518 2721
1937 2231
1937 771
...

correct output
152101730

user output
6240

Test 21

Group: 2, 4

Verdict:

input
31250 28710 19769
1 2
2 3
3 4
4 5
...

correct output
50233029

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 22

Group: 4

Verdict:

input
31250 27848 22747
16893 8747
18910 16893
30376 16893
23945 18910
...

correct output
522494382

user output
31234

Test 23

Group: 4

Verdict:

input
31250 6703 20415
23779 14085
23779 9341
14085 28511
14085 23151
...

correct output
615059214

user output
31230

Test 24

Group: 4

Verdict:

input
31250 26948 21755
344 12546
12546 11641
11641 1883
9152 12546
...

correct output
614062321

user output
31225

Test 25

Group: 2, 4

Verdict:

input
156250 71359 63141
1 2
2 3
3 4
4 5
...

correct output
360165737

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 26

Group: 4

Verdict:

input
156250 132945 97315
139434 74332
121914 74332
31473 121914
20412 139434
...

correct output
901028288

user output
156223

Test 27

Group: 4

Verdict:

input
156250 85489 5733
140340 76749
140340 98734
76749 30645
76749 72109
...

correct output
38533849

user output
0

Test 28

Group: 4

Verdict:

input
156250 143710 49348
65050 143666
143666 47977
143666 35254
47977 99013
...

correct output
615178214

user output
156228

Test 29

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
1 1 1

correct output
1

user output
1

Test 30

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
2 1 1
1 2

correct output
2

user output
2

Test 31

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
2 2 2
1 2

correct output
2

user output
2

Test 32

Group: 1, 2, 4

Verdict: ACCEPTED

input
2 1 2
1 2

correct output
1

user output
1

Test 33

Group: 1, 2, 3, 4

Verdict:

input
3 2 2
1 2
2 3

correct output
4

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 42, in <module>
    while len(o)==2:
TypeError: object of type 'int' has no len()

Test 34

Group: 1, 2, 4

Verdict: ACCEPTED

input
3 1 2
1 2
2 3

correct output
2

user output
2

Test 35

Group: 1, 2, 4

Verdict: ACCEPTED

input
3 1 3
1 2
2 3

correct output
1

user output
1

Test 36

Group: 1, 3, 4

Verdict:

input
10 4 4
1 2
1 3
3 4
1 5
...

correct output
99

user output
10

Test 37

Group: 1, 4

Verdict:

input
10 7 2
1 2
1 3
1 4
2 5
...

correct output
32

user output
0

Test 38

Group: 1, 4

Verdict:

input
10 2 4
1 2
1 3
1 4
2 5
...

correct output
72

user output
8

Test 39

Group: 1, 4

Verdict:

input
10 4 8
1 2
2 3
3 4
2 5
...

correct output
32

user output
6

Test 40

Group: 1, 4

Verdict:

input
10 3 1
1 2
1 3
1 4
2 5
...

correct output
108

user output
9

Test 41

Group: 1, 4

Verdict:

input
10 7 8
1 2
2 3
2 4
3 5
...

correct output
15

user output
6

Test 42

Group: 1, 4

Verdict:

input
10 4 10
1 2
1 3
3 4
4 5
...

correct output
40

user output
9

Test 43

Group: 1, 4

Verdict:

input
10 3 1
1 2
2 3
2 4
2 5
...

correct output
96

user output
0

Test 44

Group: 1, 4

Verdict:

input
10 6 2
1 2
1 3
2 4
3 5
...

correct output
40

user output
9

Test 45

Group: 1, 4

Verdict:

input
10 2 1
1 2
1 3
3 4
4 5
...

correct output
30

user output
9

Test 46

Group: 1, 2, 4

Verdict: ACCEPTED

input
10 1 10
1 2
2 3
3 4
4 5
...

correct output
1

user output
1

Test 47

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
3 1 1
1 2
2 3

correct output
3

user output
3

Test 48

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
3 3 3
1 2
2 3

correct output
3

user output
3

Test 49

Group: 1, 2, 4

Verdict:

input
3 2 3
1 2
2 3

correct output
2

user output
0

Test 50

Group: 1, 4

Verdict:

input
7 2 5
2 7
5 7
2 1
5 3
...

correct output
16

user output
5

Test 51

Group: 2, 4

Verdict:

input
200000 1 200000
1 2
2 3
3 4
4 5
...

correct output
1

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 52

Group: 2, 3, 4

Verdict: ACCEPTED

input
200000 1 1
1 2
2 3
3 4
4 5
...

correct output
200000

user output
200000

Test 53

Group: 2, 3, 4

Verdict: ACCEPTED

input
200000 200000 200000
1 2
2 3
3 4
4 5
...

correct output
200000

user output
200000

Test 54

Group: 2, 3, 4

Verdict:

input
200000 100000 100000
1 2
2 3
3 4
4 5
...

correct output
99930

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 42, in <module>
    while len(o)==2:
TypeError: object of type 'int' has no len()

Test 55

Group: 2, 4

Verdict:

input
200000 37563 118902
1 2
2 3
3 4
4 5
...

correct output
46321716

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 56

Group: 2, 4

Verdict:

input
200000 50775 167353
1 2
2 3
3 4
4 5
...

correct output
657702193

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 57

Group: 2, 4

Verdict:

input
200000 146383 37930
1 2
2 3
3 4
4 5
...

correct output
33730726

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 58

Group: 2, 4

Verdict:

input
200000 139297 64408
1 2
2 3
3 4
4 5
...

correct output
909823211

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 59

Group: 2, 4

Verdict:

input
200000 96291 60612
1 2
2 3
3 4
4 5
...

correct output
286070478

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 60

Group: 2, 4

Verdict:

input
199999 132295 169486
1 2
2 3
3 4
4 5
...

correct output
36849602

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 61

Group: 2, 4

Verdict:

input
199999 40570 132081
1 2
2 3
3 4
4 5
...

correct output
755473816

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 62

Group: 2, 4

Verdict:

input
200000 66666 133332
1 2
2 3
3 4
4 5
...

correct output
444555526

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 63

Group: 4

Verdict:

input
200000 74284 172335
1 2
2 3
2 4
4 5
...

correct output
813676449

user output
(empty)

Test 64

Group: 4

Verdict:

input
200000 69598 27760
1 2
2 3
3 4
2 5
...

correct output
646690172

user output
(empty)

Test 65

Group: 4

Verdict:

input
200000 49557 15601
1 2
2 3
1 4
3 5
...

correct output
566402541

user output
(empty)

Test 66

Group: 4

Verdict:

input
200000 154301 42324
1 2
2 3
1 4
4 5
...

correct output
626928627

user output
(empty)

Test 67

Group: 4

Verdict:

input
200000 73912 80615
1 2
1 3
2 4
4 5
...

correct output
173675070

user output
(empty)

Test 68

Group: 4

Verdict:

input
200000 49444 123149
1 2
2 3
1 4
4 5
...

correct output
293033335

user output
(empty)

Test 69

Group: 4

Verdict:

input
200000 68176 124500
1 2
1 3
3 4
3 5
...

correct output
18856604

user output
(empty)

Test 70

Group: 4

Verdict:

input
200000 184565 72280
1 2
1 3
2 4
4 5
...

correct output
219119175

user output
(empty)

Test 71

Group: 4

Verdict:

input
200000 94918 182877
1 2
1 3
1 4
1 5
...

correct output
752671766

user output
(empty)

Test 72

Group: 4

Verdict:

input
200000 187918 126305
1 2
1 3
3 4
1 5
...

correct output
29685111

user output
(empty)

Test 73

Group: 3, 4

Verdict:

input
200000 97734 97734
1 2
2 3
2 4
3 5
...

correct output
328993565

user output
(empty)

Test 74

Group: 3, 4

Verdict:

input
200000 148516 148516
1 2
2 3
1 4
1 5
...

correct output
127541604

user output
(empty)

Test 75

Group: 3, 4

Verdict:

input
200000 190703 190703
1 2
1 3
3 4
2 5
...

correct output
416752559

user output
(empty)

Test 76

Group: 3, 4

Verdict:

input
200000 37698 37698
1 2
2 3
1 4
2 5
...

correct output
416871404

user output
(empty)

Test 77

Group: 3, 4

Verdict:

input
200000 116531 116531
1 2
1 3
2 4
1 5
...

correct output
748204701

user output
(empty)

Test 78

Group: 3, 4

Verdict:

input
200000 27284 27284
1 2
2 3
2 4
4 5
...

correct output
76035204

user output
(empty)

Test 79

Group: 3, 4

Verdict:

input
200000 122685 122685
1 2
1 3
2 4
4 5
...

correct output
337610563

user output
(empty)

Test 80

Group: 3, 4

Verdict:

input
200000 107933 107933
1 2
2 3
2 4
4 5
...

correct output
208311114

user output
200000

Test 81

Group: 3, 4

Verdict:

input
200000 138885 138885
1 2
2 3
2 4
3 5
...

correct output
256430889

user output
200000

Test 82

Group: 3, 4

Verdict:

input
200000 58880 58880
1 2
2 3
2 4
4 5
...

correct output
768053967

user output
(empty)

Test 83

Group: 2, 4

Verdict:

input
200000 75000 90943
168194 176825
176825 120246
120246 59194
59194 193803
...

correct output
391201968

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 84

Group: 2, 4

Verdict:

input
200000 143557 105030
114244 129713
129713 100457
100457 70708
70708 178413
...

correct output
21500831

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 24, in <module>
    d=haku(x,set(),0)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  File "input/code.py", line 18, in haku
    a=haku(i,vis,d)
  [Previous line repeated 995 more times]
  File "input/code.py", line 10, in haku
    if pos==y:
RecursionError: maximum recursion depth exceeded in comparison

Test 85

Group: 1, 2, 4

Verdict: ACCEPTED

input
10 7 6
4 2
2 7
7 10
10 6
...

correct output
18

user output
18

Test 86

Group: 1, 2, 4

Verdict: ACCEPTED

input
10 1 8
1 6
6 10
10 3
3 7
...

correct output
1

user output
1