Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = [None for i in range(n - 1)]
queue = collections.deque([(1, 0)])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[edge.index((min(num, prev), max(num, prev)))]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        temp = edge.index((a, b))
        if color[temp] != None:
            continue
        else:
            if count == col:
                color[temp] = count + 1
                count += 2
            else:
                color[temp] = count
                count += 1
            queue.append((i, num))
print(max(color))
for i in range(n - 1):
    print(color[i])

Fixed submission:
import collections

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = {}
queue = collections.deque([(1, 0)])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[(prev, num)]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        if (a, b) in color.keys():
            continue
        else:
            if count == col:
                color[(a, b)] = count + 1
                count += 2
            else:
                color[(a, b)] = count
                count += 1
            queue.append((i, num))
print(max([len(graph[i]) for i in range(n + 1)]))
for i, j in edge:
    print(color[(i, j)])

Buggy python submission (verdict: Time Limit Exceeded):
import collections, sys
input = sys.stdin.readline

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = [None for i in range(n - 1)]
queue = collections.deque([[1, 0]])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[edge.index((min(num, prev), max(num, prev)))]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        temp = edge.index((a, b))
        if color[temp] != None:
            continue
        else:
            if count == col:
                color[temp] = count + 1
                count += 2
            else:
                color[temp] = count
                count += 1
            queue.append([i, num])
print(max(color))
for i in range(n - 1):
    print(color[i])

Fixed submission:
import collections

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = {}
queue = collections.deque([(1, 0)])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[(prev, num)]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        if (a, b) in color.keys():
            continue
        else:
            if count == col:
                color[(a, b)] = count + 1
                count += 2
            else:
                color[(a, b)] = count
                count += 1
            queue.append((i, num))
print(max([len(graph[i]) for i in range(n + 1)]))
for i, j in edge:
    print(color[(i, j)])

Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = [None for i in range(n - 1)]
queue = collections.deque([[1, 0]])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[edge.index((min(num, prev), max(num, prev)))]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        temp = edge.index((a, b))
        if color[temp] != None:
            continue
        else:
            if count == col:
                color[temp] = count + 1
                count += 2
            else:
                color[temp] = count
                count += 1
            queue.append([i, num])
print(max(color))
for i in range(n - 1):
    print(color[i])

Fixed submission:
import collections

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = {}
queue = collections.deque([(1, 0)])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[(prev, num)]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        if (a, b) in color.keys():
            continue
        else:
            if count == col:
                color[(a, b)] = count + 1
                count += 2
            else:
                color[(a, b)] = count
                count += 1
            queue.append((i, num))
print(max([len(graph[i]) for i in range(n + 1)]))
for i, j in edge:
    print(color[(i, j)])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ab = []
graph = {(i + 1):[] for i in range(n)}
for i in range(n - 1):
    a, b = map(int, input().split())
    ab.append([a, b])
    graph[a].append(b)
    graph[b].append(a)
color = max([len(list(graph.values())[i]) for i in range(n)])
print(color)
branch = {}
for i in graph:
    if len(graph[i]) == color:
        start = i
        break
task = [[start, 0]]
while task:
    next_check = task.pop(0)
    check = next_check[0]
    flag = False
    temp = []
    for i in range(len(graph[check])):
        if i + 1 == next_check[1]:
            flag = True
        branch[(check, graph[check][i])] = i + 1 + flag
        task.append([graph[check][i], i + 1 + flag])
        temp.append([check, graph[check][i]])
    for i in temp:
        graph[i[0]].remove(i[1])
        graph[i[1]].remove(i[0])
for i in ab:
    if (i[0], i[1]) in branch:
        print(branch[(i[0], i[1])])
    else:
        print(branch[(i[1], i[0])])

Fixed submission:
import collections

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = {}
queue = collections.deque([(1, 0)])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[(prev, num)]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        if (a, b) in color.keys():
            continue
        else:
            if count == col:
                color[(a, b)] = count + 1
                count += 2
            else:
                color[(a, b)] = count
                count += 1
            queue.append((i, num))
print(max([len(graph[i]) for i in range(n + 1)]))
for i, j in edge:
    print(color[(i, j)])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ab = []
graph = {(i + 1):[] for i in range(n)}
for i in range(n - 1):
    a, b = map(int, input().split())
    ab.append([a, b])
    graph[a].append(b)
    graph[b].append(a)
color = max([len(list(graph.values())[i]) for i in range(n)])
print(color)
branch = {}
for i in graph:
    if len(graph[i]) == color:
        start = i
        break
task = [[start, 0]]
while task:
    next_check = task.pop(0)
    check = next_check[0]
    flag = False
    temp = []
    for i in range(len(graph[check])):
        if i + 1 == next_check[1]:
            flag = True
        branch[(check, graph[check][i])] = i + 1 + flag
        task.append([graph[check][i], i + 1 + flag])
        temp.append([check, graph[check][i]])
    for i in temp:
        graph[i[0]].remove(i[1])
        graph[i[1]].remove(i[0])
for i in ab:
    if (i[0], i[1]) in branch:
        print(branch[(i[0], i[1])])
    else:
        print(branch[(i[1], i[0])])

Fixed submission:
import collections

n = int(input())
graph = [[] for i in range(n + 1)]
edge = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
color = {}
queue = collections.deque([(1, 0)])
while queue:
    temp = queue.popleft()
    num = temp[0]
    prev = temp[1]
    if prev:
        col = color[(prev, num)]
    else:
        col = 0
    count = 1
    for i in graph[num]:
        a, b = min(i, num), max(i, num)
        if (a, b) in color.keys():
            continue
        else:
            if count == col:
                color[(a, b)] = count + 1
                count += 2
            else:
                color[(a, b)] = count
                count += 1
            queue.append((i, num))
print(max([len(graph[i]) for i in range(n + 1)]))
for i, j in edge:
    print(color[(i, j)])