EPS/2024/03/11-03-24/d.py

46 lines
948 B
Python
Raw Normal View History

2024-04-15 13:45:30 +02:00
def main():
n, m = [int(i) for i in input().split()]
uv = [[int(i) for i in input().split()] for i in range(m)]
if m==n*(n-1)/2:
print(3)
out = []
u, v = uv[0]
for a, b in uv:
if (a, b) == (u, v):
out.append(1)
elif a==u or b==u:
out.append(2)
else:
out.append(3)
return " ".join([str(i) for i in out])
# Trouver un sommet de degré != n-1
degs = [0 for _ in range(n)]
for u, v in uv:
degs[u-1] += 1
degs[v-1] += 1
j=-1
for i in range(n):
if degs[i] < n-1:
j = i+1
break
if j==-1:
return
print(2)
out = []
for u, v in uv:
if u==j or v==j:
out.append(2)
else:
out.append(1)
return " ".join([str(i) for i in out])
for _ in range(int(input())):
print(main())