-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex07e3_coloring.py
105 lines (90 loc) · 878 Bytes
/
ex07e3_coloring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import math
def DFS( G,v,C ):
global n
D = [ 0 ]*n
for i in G[v]:
if C[i]==-1:
continue
D[C[i]] = 1
for i in range(n):
if D[i]==0:
C[v] = i
break
for i in G[v]:
if C[i] == -1:
DFS( G,i,C )
n,e = [int(i) for i in input().split()]
G = [ [] for i in range(n) ]
for _ in range(e):
a,b = [int(i) for i in input().split()]
G[a].append(b)
G[b].append(a)
ans = math.inf
for i in range(n):
C = [-1]*n
for j in range(n):
DFS(G,(j+i)%n,C)
ans = min( ans,max(C) )
#print(C)
print(ans+1)
'''
4 6
0 1
0 2
0 3
1 2
1 3
2 3
4 5
0 1
0 3
1 2
1 3
2 3
5 10
0 1
0 2
0 3
0 4
1 2
1 3
1 4
2 3
2 4
3 4
5 7
0 1
0 2
0 3
1 4
1 3
2 3
3 4
4 4
0 1
0 2
1 3
2 3
3 3
0 1
0 2
1 2
4 5
0 1
0 3
1 3
1 2
2 3
5 7
0 1
0 2
0 4
1 2
1 3
2 3
3 4
4 3
0 1
1 2
1 3
'''