init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
22
1D.py
Normal file
22
1D.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
n, m = map(int, input().split())
|
||||
adj = [[] for i in range(n + 1)]
|
||||
for i in range(m):
|
||||
u, v = map(int, input().split())
|
||||
adj[u].append(v)
|
||||
adj[v].append(u)
|
||||
color = [0] * (n + 1)
|
||||
for i in range(1, n + 1):
|
||||
if color[i] == 0:
|
||||
color[i] = 1
|
||||
stack = [i]
|
||||
while stack:
|
||||
u = stack.pop()
|
||||
c = color[u]
|
||||
for v in adj[u]:
|
||||
if color[v] == 0:
|
||||
color[v] = 3 - c
|
||||
stack.append(v)
|
||||
elif color[v] == c:
|
||||
print("-1")
|
||||
exit()
|
||||
print(*(color[1:]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue