Buggy python submission (verdict: Time Limit Exceeded):
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])
 
que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
color = [[] for _ in range(N+1)]
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        
        
        col = 1
        if edge[i[1]] == -1:
            que.put(i[0])
            while(True):
               
                if col in (color[i[0]] + color[start]):
                    col +=1
                    if col > maxi:
                        maxi = col
                else :
                    break
            edge[i[1]] = col
            color[i[0]].append(col)
            color[start].append(col)
print(maxi)
for i in edge[1:]:
    print(i)

Fixed submission:
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])
 
que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
start = 0
color = [[] for _ in range(N+1)]
node[1] = 0
while(True):
    if que.empty():
        break
    before = start
    start = que.get()
    col =1
    for i in tree[start]:
        
        if node[i[0]] == -1 :
            que.put(i[0])
        if edge[i[1]] == -1:
            if col == node[start]:
                col += 1
            edge[i[1]] = col
            node[i[0]] = col
            if col > maxi:
                maxi = col
            col +=1
            
print(maxi)
for i in edge[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])

que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = max([len(i) for i in tree])
color = [[i for i in range(1,maxi+1)] for _ in range(N+1)]
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        
        
        if edge[i[1]] == -1:
            col = max(color[i[0]][0],color[start][0])
            edge[i[1]] = col
            que.put(i[0])
            color[i[0]].remove(col)
            color[start].remove(col)
print(maxi)
for i in edge[1:]:
    print(i)

Fixed submission:
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])
 
que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
start = 0
color = [[] for _ in range(N+1)]
node[1] = 0
while(True):
    if que.empty():
        break
    before = start
    start = que.get()
    col =1
    for i in tree[start]:
        
        if node[i[0]] == -1 :
            que.put(i[0])
        if edge[i[1]] == -1:
            if col == node[start]:
                col += 1
            edge[i[1]] = col
            node[i[0]] = col
            if col > maxi:
                maxi = col
            col +=1
            
print(maxi)
for i in edge[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])

que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = max([len(i) for i in tree])
color = [[i for i in range(1,maxi+1)] for _ in range(N+1)]
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        
        if node[i[0]] == -1 :
            que.put(i[0])
            node[i[0]] = 1
        if edge[i[1]] == -1:
            col = max(color[i[0]][0],color[start][0])
            edge[i[1]] = col
            color[i[0]].remove(col)
            color[start].remove(col)
print(maxi)
for i in edge[1:]:
    print(i)

Fixed submission:
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])
 
que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
start = 0
color = [[] for _ in range(N+1)]
node[1] = 0
while(True):
    if que.empty():
        break
    before = start
    start = que.get()
    col =1
    for i in tree[start]:
        
        if node[i[0]] == -1 :
            que.put(i[0])
        if edge[i[1]] == -1:
            if col == node[start]:
                col += 1
            edge[i[1]] = col
            node[i[0]] = col
            if col > maxi:
                maxi = col
            col +=1
            
print(maxi)
for i in edge[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])

que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
color = [[] for _ in range(N+1)]
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        
        if node[i[0]] == -1 :
            que.put(i[0])
            node[i[0]] = 1
        col = 1
        if edge[i[1]] == -1:
            while(True):
               
                if col in (color[i[0]] + color[start]):
                    col +=1
                    if col > maxi:
                        maxi = col
                else :
                    break
            edge[i[1]] = col
            color[i[0]].append(col)
            color[start].append(col)
print(maxi)
for i in edge[1:]:
    print(i)

Fixed submission:
import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])
 
que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
start = 0
color = [[] for _ in range(N+1)]
node[1] = 0
while(True):
    if que.empty():
        break
    before = start
    start = que.get()
    col =1
    for i in tree[start]:
        
        if node[i[0]] == -1 :
            que.put(i[0])
        if edge[i[1]] == -1:
            if col == node[start]:
                col += 1
            edge[i[1]] = col
            node[i[0]] = col
            if col > maxi:
                maxi = col
            col +=1
            
print(maxi)
for i in edge[1:]:
    print(i)