Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
edges = {}
lst = [set()for i in range(n)]
vert = [set() for i in range(n)]
ans = [0 for i in range(n-1)]
for i in range(n-1):
    a,b = map(int,input().split())
    lst[a-1].add(b)
    lst[b-1].add(a)
    if a > b:
        a,b = b,a
    edges[(a,b)] = i
q = deque([1])
while q:
    x = q.popleft()
    q.extend(lst[x-1])
    while lst[x-1]:
        i = lst[x-1].pop()
        lst[i-1].discard(x)
        a = min(x,i)
        b = max(x,i)
        for j in range(1,n):
            if not (j in vert[x-1] or j in vert[i-1]):
                vert[x-1].add(j)
                vert[i-1].add(j)
                ans[edges[(a,b)]] = j
                break
print(max(ans))
for i in range(len(ans)):
    print(ans[i])


Fixed submission:
n = int(input())
graph = [[] for _ in range(n+1)]
for i in range(1,n):
    a,b = map(int,input().split())
    graph[a].append((i,b))
    graph[b].append((i,a))
colors = [0 for _ in range(n)]
parents = [0]*(n+1)
stack = [(1,0)]
while stack:
    x,c = stack.pop()
    color = 1
    for i,y in graph[x]:
        if parents[x] == y:
            continue
        else:
            parents[y] = x
            if color == c:
                color += 1
            colors[i] = color
            stack.append((y,color))
            color += 1
print(max(colors))
for i in range(1,n):
    print(colors[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
edges = {}
lst = [[]for i in range(n)]
vert = [set() for i in range(n)]
ans = [0 for i in range(n-1)]
for i in range(n-1):
    a,b = map(int,input().split())
    lst[a-1].append(b)
    lst[b-1].append(a)
    if a > b:
        a,b = b,a
    edges[(a,b)] = i
q = deque([1])
while q:
    x = q.popleft()
    q.extend(lst[x-1])
    for i in lst[x-1]:
        lst[x-1].remove(i)
        lst[i-1].remove(x)
        a = min(x,i)
        b = max(x,i)
        for j in range(1,n):
            if not (j in vert[x-1] or j in vert[i-1]):
                vert[x-1].add(j)
                vert[i-1].add(j)
                ans[edges[(a,b)]] = j
                break
print(max(ans))
for i in range(len(ans)):
    print(ans[i])


Fixed submission:
n = int(input())
graph = [[] for _ in range(n+1)]
for i in range(1,n):
    a,b = map(int,input().split())
    graph[a].append((i,b))
    graph[b].append((i,a))
colors = [0 for _ in range(n)]
parents = [0]*(n+1)
stack = [(1,0)]
while stack:
    x,c = stack.pop()
    color = 1
    for i,y in graph[x]:
        if parents[x] == y:
            continue
        else:
            parents[y] = x
            if color == c:
                color += 1
            colors[i] = color
            stack.append((y,color))
            color += 1
print(max(colors))
for i in range(1,n):
    print(colors[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
edges = {}
lst = [[]for i in range(n)]
vert = [[]for i in range(n)]
ans = [0 for i in range(n-1)]
for i in range(n-1):
    a,b = map(int,input().split())
    lst[a-1].append(b)
    lst[b-1].append(a)
    if a > b:
        a,b = b,a
    edges[(a,b)] = i
q = deque([1])
while q:
    x = q.popleft()
    q.extend(lst[x-1])
    for i in lst[x-1]:
        lst[x-1].remove(i)
        lst[i-1].remove(x)
        a = min(x,i)
        b = max(x,i)
        for j in range(1,n):
            if not (j in vert[x-1] or j in vert[i-1]):
                vert[x-1].append(j)
                vert[i-1].append(j)
                ans[edges[(a,b)]] = j
                break
print(max(ans))
for i in range(len(ans)):
    print(ans[i])


Fixed submission:
n = int(input())
graph = [[] for _ in range(n+1)]
for i in range(1,n):
    a,b = map(int,input().split())
    graph[a].append((i,b))
    graph[b].append((i,a))
colors = [0 for _ in range(n)]
parents = [0]*(n+1)
stack = [(1,0)]
while stack:
    x,c = stack.pop()
    color = 1
    for i,y in graph[x]:
        if parents[x] == y:
            continue
        else:
            parents[y] = x
            if color == c:
                color += 1
            colors[i] = color
            stack.append((y,color))
            color += 1
print(max(colors))
for i in range(1,n):
    print(colors[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
edges = {}
lst = [[]for i in range(n)]
vert = [[]for i in range(n)]
ans = [0 for i in range(n-1)]
for i in range(n-1):
    a,b = map(int,input().split())
    lst[a-1].append(b)
    lst[b-1].append(a)
    if a > b:
        a,b = b,a
    edges[(a,b)] = i
q = deque([1])
while q:
    x = q.popleft()
    q.extend(lst[x-1])
    for i in lst[x-1]:
        lst[x-1].remove(i)
        lst[i-1].remove(x)
        a = min(x,i)
        b = max(x,i)
        for j in range(1,n):
            if not (j in vert[x-1] or j in vert[i-1]):
                vert[x-1].append(j)
                vert[i-1].append(j)
                ans[edges[(a,b)]] = j
                break
print(max(ans))
for i in range(len(ans)):
    print(ans[i])


Fixed submission:
n = int(input())
graph = [[] for _ in range(n+1)]
for i in range(1,n):
    a,b = map(int,input().split())
    graph[a].append((i,b))
    graph[b].append((i,a))
colors = [0 for _ in range(n)]
parents = [0]*(n+1)
stack = [(1,0)]
while stack:
    x,c = stack.pop()
    color = 1
    for i,y in graph[x]:
        if parents[x] == y:
            continue
        else:
            parents[y] = x
            if color == c:
                color += 1
            colors[i] = color
            stack.append((y,color))
            color += 1
print(max(colors))
for i in range(1,n):
    print(colors[i])