Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
connected = [[] for _ in range(N)]
ans = [0] * (N-1)
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append([b,i])
    connected[b-1].append([a,i])
colors = max(len(d) for d in connected)
print(colors)
init = 1
d = deque()
parents = deque()
for edge in connected[0]:
    ans[edge[1]] = init
    init += 1
    d.append(edge)
    parents.append(1)
while d:
    temp = d.popleft()
    parent = parents.popleft()
    if len(connected[temp[0]-1]) > 1:
        used = deque(range(1,colors+1))
        used.remove(ans[temp[1]])
        for edge in connected[temp[0]-1]:
            if edge[0] != parent:
                ans[edge[1]] = used.popleft()
                d.append(edge)
                parents.append(temp[0])
for i in range(N-1):
    print(ans[i])

Fixed submission:
from collections import deque
N = int(input())
connected = [[] for _ in range(N)]
ans = [0] * (N-1)
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append([b,i])
    connected[b-1].append([a,i])
colors = max(len(d) for d in connected)
print(colors)
init = 1
d = deque()
parents = deque()
for edge in connected[0]:
    ans[edge[1]] = init
    init += 1
    d.append(edge)
    parents.append(1)
while d:
    temp = d.popleft()
    parent = parents.popleft()
    l = len(connected[temp[0]-1])
    if l > 1:
        used = deque(range(1,l+1))
        for edge in connected[temp[0]-1]:
            if edge[0] != parent:
                color = used.popleft()
                if color == ans[temp[1]]:
                    ans[edge[1]] = used.popleft()
                else:
                    ans[edge[1]] = color
                d.append(edge)
                parents.append(temp[0])
for i in range(N-1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
connected = [[] for _ in range(N)]
ans = [0] * (N-1)
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append([b,i])
    connected[b-1].append([a,i])
colors = max(len(d) for d in connected)
print(colors)
init = 1
d = deque()
parents = deque()
for edge in connected[0]:
    ans[edge[1]] = init
    init += 1
    d.append(edge)
    parents.append(1)
while d:
    temp = d.popleft()
    parent = parents.popleft()
    used = deque(range(1,colors+1))
    used.remove(ans[temp[1]])
    if len(connected[temp[0]-1]) > 1:
        for edge in connected[temp[0]-1]:
            if edge[0] != parent:
                ans[edge[1]] = used.popleft()
                d.append(edge)
                parents.append(temp[0])
for i in range(N-1):
    print(ans[i])

Fixed submission:
from collections import deque
N = int(input())
connected = [[] for _ in range(N)]
ans = [0] * (N-1)
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append([b,i])
    connected[b-1].append([a,i])
colors = max(len(d) for d in connected)
print(colors)
init = 1
d = deque()
parents = deque()
for edge in connected[0]:
    ans[edge[1]] = init
    init += 1
    d.append(edge)
    parents.append(1)
while d:
    temp = d.popleft()
    parent = parents.popleft()
    l = len(connected[temp[0]-1])
    if l > 1:
        used = deque(range(1,l+1))
        for edge in connected[temp[0]-1]:
            if edge[0] != parent:
                color = used.popleft()
                if color == ans[temp[1]]:
                    ans[edge[1]] = used.popleft()
                else:
                    ans[edge[1]] = color
                d.append(edge)
                parents.append(temp[0])
for i in range(N-1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
connected = [[] for _ in range(N)]
ans = [0] * (N-1)
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append([b,i])
    connected[b-1].append([a,i])
colors = max(len(d) for d in connected)
print(colors)
init = 1
d = deque()
parents = deque()
for edge in connected[0]:
    ans[edge[1]] = init
    init += 1
    d.append(edge)
    parents.append(1)
while d:
    temp = d.popleft()
    parent = parents.popleft()
    used = deque(range(1,colors+1))
    used.remove(ans[temp[1]])
    if len(connected[temp[0]-1]) > 1:
        for edge in connected[temp[0]-1]:
            if edge[0] != parent:
                ans[edge[1]] = used.popleft()
                d.append(edge)
                parents.append(temp[0])
for i in range(N-1):
    print(ans[i])

Fixed submission:
from collections import deque
N = int(input())
connected = [[] for _ in range(N)]
ans = [0] * (N-1)
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append([b,i])
    connected[b-1].append([a,i])
colors = max(len(d) for d in connected)
print(colors)
init = 1
d = deque()
parents = deque()
for edge in connected[0]:
    ans[edge[1]] = init
    init += 1
    d.append(edge)
    parents.append(1)
while d:
    temp = d.popleft()
    parent = parents.popleft()
    l = len(connected[temp[0]-1])
    if l > 1:
        used = deque(range(1,l+1))
        for edge in connected[temp[0]-1]:
            if edge[0] != parent:
                color = used.popleft()
                if color == ans[temp[1]]:
                    ans[edge[1]] = used.popleft()
                else:
                    ans[edge[1]] = color
                d.append(edge)
                parents.append(temp[0])
for i in range(N-1):
    print(ans[i])