Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
ki = [[]for j in range(n)]
for i in range(n-1):
	    a,b=map(int,input().split())
	    a-=1
	    b-=1
	    ki[a].append([b,i])
	    ki[b].append([a,i])


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,-1)
print(*clist)

Buggy submission (verdict: Runtime Error):
n = int(input())
ki = [[]for j in range(n)]
for i in range(n-1):
	    a,b=map(int,input().split())
	    a-=1
	    b-=1
	    ki[a].append([b,i])
	    ki[b].append([a,i])


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,-1)
print(*clist)

Buggy submission (verdict: Runtime Error):
n = int(input())
ki = [[]for j in range(n)]
for i in range(n-1):
	    a,b=map(int,input().split())
	    a-=1
	    b-=1
	    ki[a].append([b,i])
	    ki[b].append([a,i])


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,-1)
for i in range(n-1):
    print(clist[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ki = [[]for j in range(n)]
for i in range(n-1):
	    a,b=map(int,input().split())
	    a-=1
	    b-=1
	    ki[a].append([b,i])
	    ki[b].append([a,i])


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,0)
for i in range(n-1):
    print(clist[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ki = [[]for j in range(n)]
for i in range(n-1):
	    a,b=map(int,input().split())
	    a-=1
	    b-=1
	    ki[a].append([b,i])
	    ki[b].append([a,i])


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color = 1
	    for next,id in ki[now]:
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    
	    	    
dfs(0,0)
for i in range(n-1):
    print(clist[i])