Submission details
Task:Astralis session I
Sender:aalto26bw_001
Submission time:2026-09-09 17:45:56 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.09 sdetails
#20.09 sdetails
#30.09 sdetails
#40.09 sdetails
#50.09 sdetails
#60.09 sdetails
#70.09 sdetails
#80.09 sdetails
#90.09 sdetails
#100.09 sdetails
#110.09 sdetails
#120.09 sdetails
#130.09 sdetails
#140.09 sdetails
#150.09 sdetails
#160.09 sdetails
#170.09 sdetails
#180.09 sdetails
#190.09 sdetails
#200.09 sdetails
#210.09 sdetails
#220.11 sdetails
#230.10 sdetails
#240.09 sdetails
#250.11 sdetails
#260.09 sdetails
#270.11 sdetails
#280.09 sdetails
#290.10 sdetails
#300.09 sdetails
#310.10 sdetails
#320.10 sdetails
#330.10 sdetails
#340.13 sdetails
#350.10 sdetails
#360.12 sdetails
#370.10 sdetails
#380.13 sdetails
#390.10 sdetails
#400.10 sdetails
#410.15 sdetails
#420.12 sdetails
#430.17 sdetails
#440.12 sdetails
#450.12 sdetails
#460.20 sdetails
#470.26 sdetails
#480.21 sdetails
#490.16 sdetails
#500.16 sdetails
#510.13 sdetails
#52--details
#53--details
#54--details
#55--details
#56--details
#57--details
#58--details
#59--details
#60--details
#61--details

Code

from dataclasses import dataclass

@dataclass
class Path:
    left: int
    right: int

# Read
n = int(input())

# Int : Int
# Represents connections.
connections: list[Path] = []
sides = {}

for i in range(0, (n - 1)):
    read = input().split(" ")
    val1 = int(read[0])
    val2 = int(read[1])

    connections.append(Path(val1, val2))

# For this node, where is it connected.
def findConnections(look: int, looked: int) -> list[int]:
    conn = []
    for i in connections:
        if (i.right != looked and i.left == look):
            conn.append(i.right)            
        if ((i.left != looked) and (i.right == look)):
            conn.append(i.left)
    return conn

# Iterative loop
def inspect(node: int, lastOne: int, letter: str) -> int:
    conn = findConnections(node, lastOne)
    print("For node "+str(node))
    final = 0
    for i in conn:
        sides.update({i : letter})
        final = inspect(i, node, letter) + 1
    return final


foundMiddle = False

# Find middle
for i in connections:
    # The current connection we are inspecting.
    current = i
    sides.update({i.left : "U"})
    sides.update({i.right : "M"})

    # How many nodes are on both sides.
    nodesOnRight = inspect(current.left, current.right, "U")
    nodesOnLeft = inspect(current.right, current.left, "M")

    if nodesOnRight == nodesOnLeft:
        foundMiddle = True
        break

if foundMiddle:
    print("Yes")
    s = ""
    for i in sides.values():
        s += str(i)
    print(s)

else:
    print("No")

Test details

Test 1

Verdict:

input
2
1 2

correct output
Yes
MU

user output
For node 1
For node 2
Yes
UM

Test 2

Verdict:

input
6
1 3
2 3
2 6
4 6
...

correct output
No

user output
For node 1
For node 3
For node 2
For node 6
For node 4
...

Test 3

Verdict:

input
6
1 2
2 3
3 6
2 4
...

correct output
No

user output
For node 1
For node 5
For node 2
For node 3
For node 6
...

Test 4

Verdict:

input
6
1 6
1 4
2 4
2 3
...

correct output
No

user output
For node 1
For node 4
For node 2
For node 3
For node 5
...

Test 5

Verdict:

input
6
2 4
1 4
2 6
1 3
...

correct output
Yes
MUMUMU

user output
For node 2
For node 6
For node 4
For node 1
For node 3
...

Test 6

Verdict:

input
8
1 8
5 8
3 5
3 6
...

correct output
Yes
MUMUMUUM

user output
For node 1
For node 8
For node 5
For node 3
For node 6
...

Test 7

Verdict:

input
8
1 4
1 6
3 6
1 5
...

correct output
Yes
MUUMMUMU

user output
For node 1
For node 6
For node 3
For node 8
For node 2
...

Test 8

Verdict:

input
8
1 7
1 3
1 8
2 8
...

correct output
No

user output
For node 1
For node 3
For node 4
For node 8
For node 2
...

Test 9

Verdict:

input
8
2 3
3 8
7 8
5 8
...

correct output
Yes
MMUMUMUU

user output
For node 2
For node 6
For node 1
For node 4
For node 3
...

Test 10

Verdict:

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

correct output
Yes
MUMMMUMUUU

user output
For node 4
For node 7
For node 1
For node 5
For node 3
...

Test 11

Verdict:

input
10
3 4
4 5
4 8
4 10
...

correct output
No

user output
For node 3
For node 2
For node 6
For node 1
For node 4
...

Test 12

Verdict:

input
10
1 3
2 3
2 6
6 10
...

correct output
Yes
MMMUUMUMUU

user output
For node 1
For node 3
For node 2
For node 6
For node 10
...

Test 13

Verdict:

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

correct output
No

user output
For node 1
For node 3
For node 7
For node 4
For node 10
...

Test 14

Verdict:

input
10
1 6
1 4
2 4
2 9
...

correct output
No

user output
For node 1
For node 4
For node 2
For node 9
For node 5
...

Test 15

Verdict:

input
12
4 10
4 11
9 11
6 11
...

correct output
Yes
UUUMUMMUMUMM

user output
For node 4
For node 11
For node 9
For node 6
For node 12
...

Test 16

Verdict:

input
12
1 2
1 8
5 8
3 8
...

correct output
Yes
MUMMMUUMUUUM

user output
For node 1
For node 8
For node 5
For node 3
For node 4
...

Test 17

Verdict:

input
14
9 12
6 9
3 6
3 11
...

correct output
No

user output
For node 9
For node 6
For node 3
For node 11
For node 7
...

Test 18

Verdict:

input
14
13 14
7 13
3 7
7 10
...

correct output
Yes
UMMMMUMUUMUUMU

user output
For node 13
For node 7
For node 3
For node 4
For node 10
...

Test 19

Verdict:

input
14
1 3
3 8
3 7
8 9
...

correct output
Yes
MUUUMMUUUMMMMU

user output
For node 1
For node 5
For node 13
For node 12
For node 11
...

Test 20

Verdict:

input
16
4 12
1 4
12 16
11 12
...

correct output
No

user output
For node 4
For node 1
For node 13
For node 15
For node 9
...

Test 21

Verdict:

input
18
12 13
13 17
8 13
12 15
...

correct output
No

user output
For node 12
For node 15
For node 14
For node 6
For node 18
...

Test 22

Verdict:

input
100
24 28
28 65
28 58
54 65
...

correct output
Yes
MMUUMUMMUMUMUUMUUMMUUUMMMUUUUM...

user output
For node 24
For node 31
For node 64
For node 69
For node 59
...

Test 23

Verdict:

input
100
57 98
24 57
24 34
25 34
...

correct output
Yes
MUUMUMUUUMMUMMUMUMMMMMUUUMUUMM...

user output
For node 57
For node 24
For node 34
For node 25
For node 5
...

Test 24

Verdict:

input
100
6 41
6 20
6 18
6 88
...

correct output
Yes
MMMMUMMMUMUUMMUUUMMMUUUUUMUUUU...

user output
For node 6
For node 20
For node 77
For node 75
For node 95
...

Test 25

Verdict:

input
100
24 100
92 100
62 100
88 100
...

correct output
Yes
MUUMMUUMMUMUMUMUUUUUUMMMUMUMUM...

user output
For node 24
For node 87
For node 97
For node 80
For node 94
...

Test 26

Verdict:

input
100
65 83
68 83
65 87
21 65
...

correct output
No

user output
For node 65
For node 87
For node 45
For node 64
For node 34
...

Test 27

Verdict:

input
100
12 87
12 56
41 56
11 41
...

correct output
No

user output
For node 12
For node 56
For node 41
For node 11
For node 21
...

Test 28

Verdict:

input
100
13 29
13 38
13 34
10 13
...

correct output
Yes
MMMMUUMUMMUUMMUUMMMUMMUUMMUUUU...

user output
For node 13
For node 38
For node 46
For node 52
For node 87
...

Test 29

Verdict:

input
100
77 94
52 77
53 77
53 56
...

correct output
No

user output
For node 77
For node 52
For node 11
For node 50
For node 48
...

Test 30

Verdict:

input
100
56 59
56 76
17 76
17 75
...

correct output
No

user output
For node 56
For node 76
For node 17
For node 75
For node 9
...

Test 31

Verdict:

input
100
19 70
70 86
27 86
27 31
...

correct output
Yes
MMMMUMMUMMUUMMUMUUUMMMUMUMUUMU...

user output
For node 19
For node 70
For node 86
For node 27
For node 31
...

Test 32

Verdict:

input
200
28 148
28 122
28 137
122 178
...

correct output
Yes
UUMUMMMUUMMUMMMUMMUUMUMUMUMMMU...

user output
For node 28
For node 122
For node 178
For node 57
For node 106
...

Test 33

Verdict:

input
200
57 98
57 153
34 153
98 109
...

correct output
No

user output
For node 57
For node 153
For node 34
For node 105
For node 20
...

Test 34

Verdict:

input
200
6 177
6 20
6 158
88 158
...

correct output
Yes
MUUMUMMMUMUUMUUUUUUMUMMMMUUMMU...

user output
For node 6
For node 20
For node 156
For node 85
For node 152
...

Test 35

Verdict:

input
200
142 178
119 142
142 155
119 140
...

correct output
No

user output
For node 142
For node 119
For node 140
For node 7
For node 85
...

Test 36

Verdict:

input
200
83 150
68 83
68 158
135 158
...

correct output
Yes
MMMUUUUUUMUUUMUMUUMMMUMUUUMMUM...

user output
For node 83
For node 68
For node 158
For node 135
For node 146
...

Test 37

Verdict:

input
200
20 177
87 177
121 177
137 177
...

correct output
Yes
MMUMUMMMUUUMUMUMMMUMUMUUUUUUMM...

user output
For node 20
For node 147
For node 179
For node 133
For node 197
...

Test 38

Verdict:

input
200
13 139
13 38
13 34
10 38
...

correct output
Yes
MUMMUUMUUMUUMMUMMMMUMMUMUUUMMU...

user output
For node 13
For node 38
For node 10
For node 116
For node 86
...

Test 39

Verdict:

input
200
84 198
77 198
52 198
53 77
...

correct output
Yes
MMMUMUMMMUUUUMUUUMMMMMUMUMUUUU...

user output
For node 84
For node 106
For node 67
For node 141
For node 24
...

Test 40

Verdict:

input
200
56 112
76 112
56 182
56 114
...

correct output
No

user output
For node 56
For node 182
For node 114
For node 175
For node 193
...

Test 41

Verdict:

input
200
19 114
19 70
70 86
19 27
...

correct output
Yes
MMMUMUUUUUMUMMMMMMMUUMMUMMMMUM...

user output
For node 19
For node 70
For node 86
For node 30
For node 147
...

Test 42

Verdict:

input
1000
811 883
397 883
137 397
546 883
...

correct output
Yes
MMMMMUUMUMUUUUUUMUMUMMMMUMMUMM...

user output
For node 811
For node 969
For node 599
For node 743
For node 68
...

Test 43

Verdict:

input
1000
393 736
393 398
398 407
351 393
...

correct output
No

user output
For node 393
For node 398
For node 407
For node 146
For node 968
...

Test 44

Verdict:

input
1000
507 955
340 955
507 813
418 955
...

correct output
No

user output
For node 507
For node 813
For node 505
For node 684
For node 282
...

Test 45

Verdict:

input
1000
230 974
230 440
440 752
752 977
...

correct output
No

user output
For node 230
For node 440
For node 752
For node 977
For node 500
...

Test 46

Verdict:

input
1000
406 944
778 944
68 944
545 778
...

correct output
Yes
UMUMMUMUUMUUMUUMUMMUUMUUMUUUUM...

user output
For node 406
For node 499
For node 995
For node 925
For node 685
...

Test 47

Verdict:

input
1000
771 921
368 921
121 921
121 810
...

correct output
Yes
UMMUUUUUMUMMUMUMUUUUMMMMUMUUMM...

user output
For node 771
For node 571
For node 556
For node 848
For node 880
...

Test 48

Verdict:

input
1000
290 518
518 738
518 554
290 997
...

correct output
No

user output
For node 290
For node 997
For node 691
For node 138
For node 658
...

Test 49

Verdict:

input
1000
370 791
390 791
390 835
585 835
...

correct output
Yes
MMUUUUUMMMUMMUMMMMMMUUMMUMMMMU...

user output
For node 370
For node 791
For node 390
For node 835
For node 585
...

Test 50

Verdict:

input
1000
111 804
778 804
520 804
520 829
...

correct output
Yes
MMMUMUUUUUMMMUMMMMMUUMMUMMUUUU...

user output
For node 111
For node 359
For node 447
For node 834
For node 800
...

Test 51

Verdict:

input
1000
627 823
399 627
27 399
27 945
...

correct output
Yes
MMUMMMMUUMMUUMUUUUUMUMMUMMMMMU...

user output
For node 627
For node 399
For node 27
For node 945
For node 278
...

Test 52

Verdict:

input
100000
26991 68205
21905 68205
3029 26991
21905 29288
...

correct output
No

user output
(empty)

Test 53

Verdict:

input
100000
41845 94618
94618 96640
65841 94618
9894 96640
...

correct output
Yes
UMUUUMMUUUMMUMMUMUMMMUMMMUMUMU...

user output
(empty)

Test 54

Verdict:

input
100000
11081 29940
11081 90273
11081 56653
56653 73314
...

correct output
Yes
UMMUUMMMUUMMMMMUUMMUUUMUMMMUUU...

user output
(empty)

Test 55

Verdict:

input
100000
27549 31873
27549 48777
48777 71940
48777 59266
...

correct output
Yes
MMMMUUMUUMUMUMMUUUMMUMMMUMUUUM...

user output
(empty)

Test 56

Verdict:

input
100000
2460 57807
2460 59927
56550 59927
35046 56550
...

correct output
Yes
MMMUUMMUMMUUUMMUMUMMMUMUUMUMUM...

user output
(empty)

Test 57

Verdict:

input
100000
13089 77222
77222 89616
36711 89616
27645 77222
...

correct output
Yes
UMUUUMMMUUUUMMUMMMUUMMUUMUMUMU...

user output
(empty)

Test 58

Verdict:

input
100000
35805 70440
70440 82302
64483 82302
64483 96767
...

correct output
Yes
MMMUUMMMUUUMMMUUMUUMUMMUUUMUUM...

user output
(empty)

Test 59

Verdict:

input
100000
16206 68738
37820 68738
55519 68738
55519 77758
...

correct output
Yes
MMUUUMUUMUUMUUMUMMMMMUMUUUUUUU...

user output
(empty)

Test 60

Verdict:

input
100000
47137 86808
47137 80136
47137 73346
73346 78144
...

correct output
Yes
UUMUMMUUUUMMMMMMMMUUMMMMMMUUMU...

user output
(empty)

Test 61

Verdict:

input
100000
39438 53660
53660 60245
20924 60245
20924 38669
...

correct output
No

user output
(empty)