Submission details
Task:Coloring
Sender:Casinosort
Submission time:2025-11-08 16:53:16 +0200
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.29 sdetails
#3--details
#4--details
#50.04 sdetails
#60.04 sdetails
#7--details
#8--details
#9--details
#10--details
#11--details
#12--details
#13--details
#14--details
#15--details
#16--details
#17--details
#18--details
#19--details
#20--details
#21--details
#22--details
#23--details
#24--details
#25--details
#26--details
#27--details

Code

line = input().split()

n = int(line[0])
m = int(line[1])

edges = []
neighbors = [[] for _k in range(n)]
colors = [0 for _k in range(n)]

for _k in range(0, m):
    line = input().split()
    v1, v2 = int(line[0])-1, int(line[1])-1
    neighbors[v1].append(v2)
    neighbors[v2].append(v1) 

    """
    if neighbors[v1-1] == []:
        neighbors[v1-1] = [v2]
    else:
        neighbors[v1-1].append(v2)
    if neighbors[v2-1] == []:
        neighbors[v2-1] = [v1]
    else:
        neighbors[v2-1].append(v1)
    """

node = 0
colors[node] = 1
#print(neighbors)
checked = [False for _k in range(n)]

while False in checked:

    checked[node] = True

    color_opts = [1,2,3,4,5,6]

    next_node = 0    
    for neigh in neighbors[node]:
        if not checked[neigh]:
            next_node = neigh
        cn = colors[neigh]
        if cn != 0 and (cn in color_opts):
            color_opts.remove(colors[neigh])
    
    colors[node] = min(color_opts)
    node = next_node


print(colors)

Test details

Test 1

Verdict:

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

correct output
2 3 1 2 1

user output
[1, 3, 2, 2, 1]

Test 2

Verdict:

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

correct output
4 3 2 3 2 3 2 3 2 3 2 3 2 3 2 ...

user output
[1, 4, 3, 1, 3, 1, 3, 1, 3, 1,...

Test 3

Verdict:

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

correct output
3 2 1 4 1 4 1 3 2 4 3 2 1 5 3 ...

user output
(empty)

Test 4

Verdict:

input
81251 200000
1 6251
6251 12501
12501 18751
18751 25001
...

correct output
3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 ...

user output
(empty)

Test 5

Verdict:

input
2 1
1 2

correct output
2 1

user output
[1, 2]

Test 6

Verdict:

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

correct output
1 3 3 2 1

user output
[1, 2, 2, 3, 1]

Test 7

Verdict:

input
9 10
4 6
5 8
9 6
5 4
...

correct output
3 2 1 1 3 2 1 1 1

user output
(empty)

Test 8

Verdict:

input
65 100
34 52
42 65
48 6
62 63
...

correct output
2 2 3 2 1 1 4 1 5 3 3 4 3 1 1 ...

user output
(empty)

Test 9

Verdict:

input
661 1000
102 270
29 1
235 291
1 28
...

correct output
2 1 1 1 2 1 1 2 1 2 2 2 3 2 3 ...

user output
(empty)

Test 10

Verdict:

input
6658 10000
6255 6351
6240 811
5121 5120
562 563
...

correct output
3 3 1 1 2 2 1 2 3 1 3 3 2 1 2 ...

user output
(empty)

Test 11

Verdict:

input
66713 100002
17616 53797
36477 36478
9289 9288
30331 12908
...

correct output
2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 ...

user output
(empty)

Test 12

Verdict:

input
133153 199900
84918 102523
65880 121666
112752 112751
119806 92639
...

correct output
1 3 1 1 1 2 1 2 1 2 1 2 1 2 1 ...

user output
(empty)

Test 13

Verdict:

input
132902 199904
38449 38448
103004 31700
24769 12112
102436 54041
...

correct output
1 1 2 1 1 3 1 2 1 1 1 1 1 1 1 ...

user output
(empty)

Test 14

Verdict:

input
133659 199900
106579 112407
107263 107093
11493 44214
15803 15804
...

correct output
2 2 1 1 1 2 1 1 1 1 2 1 1 2 3 ...

user output
(empty)

Test 15

Verdict:

input
36 85
28 29
8 9
36 30
14 8
...

correct output
1 3 2 1 3 2 3 2 1 3 2 1 2 1 3 ...

user output
(empty)

Test 16

Verdict:

input
40000 119201
16810 16610
34321 34120
38157 37956
24084 23883
...

correct output
3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 ...

user output
(empty)

Test 17

Verdict:

input
80000 199993
29955 9954
47408 27408
51231 51232
37204 37205
...

correct output
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ...

user output
(empty)

Test 18

Verdict:

input
15 35
3 2
3 4
4 2
5 4
...

correct output
2 1 3 2 4 5 2 3 4 3 2 4 3 2 1

user output
(empty)

Test 19

Verdict:

input
143 352
3 2
3 4
4 2
5 4
...

correct output
1 3 4 1 5 2 1 4 5 1 2 4 3 2 1 ...

user output
(empty)

Test 20

Verdict:

input
81256 198855
3 2
3 4
4 2
5 4
...

correct output
1 3 4 1 5 2 1 4 5 1 2 4 3 2 1 ...

user output
(empty)

Test 21

Verdict:

input
15 33
3 2
3 4
4 2
5 4
...

correct output
1 1 3 2 4 3 2 1 3 5 4 3 2 1 2

user output
(empty)

Test 22

Verdict:

input
137 326
3 2
3 4
4 2
5 4
...

correct output
1 1 3 2 4 3 2 1 3 5 4 3 2 1 2 ...

user output
(empty)

Test 23

Verdict:

input
82312 198211
3 2
3 4
4 2
5 4
...

correct output
1 1 3 2 4 3 2 1 3 5 4 3 2 1 2 ...

user output
(empty)

Test 24

Verdict:

input
512 1025
2 13
13 3
2 14
14 3
...

correct output
2 1 2 5 1 3 4 2 1 2 1 4 3 3 3 ...

user output
(empty)

Test 25

Verdict:

input
15342 30761
2 13
13 3
2 14
14 3
...

correct output
1 3 2 5 1 3 4 2 1 2 1 4 1 1 1 ...

user output
(empty)

Test 26

Verdict:

input
51148 102547
2 13
13 3
2 14
14 3
...

correct output
1 3 2 5 1 3 4 2 1 2 1 4 1 1 1 ...

user output
(empty)

Test 27

Verdict:

input
99735 199964
2 13
13 3
2 14
14 3
...

correct output
1 3 2 5 1 3 4 2 1 2 1 4 1 1 1 ...

user output
(empty)