Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)
ten_col =[[] for i in range(N)]

def dfs(start,now):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            if new_col in ten_col[now-1]:
                new_col += 1
            ten_col[now-1].append(new_col)
            ten_col[future-1].append(new_col)
            ans[i] = new_col
            new_col += 1

            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

N = int(input())
a_list=[]
b_list=[]
graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)
ten_col =[[] for i in range(N)]
def dfs(start,now):
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while new_col in ten_col[now-1]:
                new_col += 1
            ten_col[now-1].append(new_col)
            ten_col[future-1].append(new_col)
            ans[i] = new_col

            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

N = int(input())
a_list=[]
b_list=[]
graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now):
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while new_col in ten_col[now-1]:
                new_col += 1
            ten_col[now-1].append(new_col)
            ten_col[future-1].append(new_col)
            ans[i] = new_col

            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

N = int(input())
a_list=[]
b_list=[]
graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now):
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ten_col[future-1].append(new_col)
                    ans[i] = new_col
                    break
                else:
                    new_col += 1
            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

N = int(input())
a_list=[]
b_list=[]

for i in range(N-1):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

graph = [[] for i in range(N)]
for i in range(N-1):
    graph[a_list[i]-1].append((b_list[i],i))
    graph[b_list[i]-1].append((a_list[i],i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now):
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ten_col[future-1].append(new_col)
                    ans[i] = new_col
                    break
                else:
                    new_col += 1
            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N = int(input())
a_list=[]
b_list=[]
for i in range(N-1):
    ab = list(map(int,input().split()))
    a_list.append(ab[0])
    b_list.append(ab[1])

graph = [[] for i in range(N)]
for i in range(N-1):
    graph[a_list[i]-1].append((b_list[i],i))
    graph[b_list[i]-1].append((a_list[i],i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now):
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ten_col[future-1].append(new_col)
                    ans[i] = new_col
                    break
                else:
                    new_col += 1
            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N = int(input())
ab_list = [list(map(int,input().split())) for i in range(N-1)]

ab_list.sort()

graph = [[] for i in range(N)]
for i in range(N-1):
    graph[ab_list[i][0]-1].append((ab_list[i][1],i))
    graph[ab_list[i][1]-1].append((ab_list[i][0],i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now,color):
    ten_col[now-1].append(color)
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ten_col[future-1].append(new_col)
                    ans[i] = new_col
                    break
                else:
                    new_col += 1
            dfs(now,future,new_col)
            
dfs(-1,1,0)
print(max(ans))
for i in ans:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N = int(input())
ab_list = [list(map(int,input().split())) for i in range(N-1)]

ab_list.sort()

graph = [[] for i in range(N)]
for i in range(N-1):
    graph[ab_list[i][0]-1].append((ab_list[i][1],i))
    graph[ab_list[i][1]-1].append((ab_list[i][0],i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now,color):
    ten_col[now-1].append(color)
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ans[i] = new_col
                    break
                else:
                    new_col += 1
            dfs(now,future,new_col)
            
dfs(-1,1,0)
print(max(ans))
for i in ans:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
N = int(input())
ab_list = [list(map(int,input().split())) for i in range(N-1)]

ab_list.sort()

graph = [[] for i in range(N)]
for i in range(N-1):
    graph[ab_list[i][0]-1].append((ab_list[i][1],i))
    graph[ab_list[i][1]-1].append((ab_list[i][0],i))
    
ans = [0 for i in range(N-1)]
ten_col = [[] for i in range(N)]
def dfs(start,now,color):
    ten_col[now-1]=[color]
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ans[i] = new_col
                    break
                else:
                    new_col += 1
            dfs(now,future,new_col)
            
dfs(-1,1,0)
print(max(ans))
for i in ans:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
N = int(input())
ab_list = [list(map(int,input().split())) for i in range(N-1)]

ab_list.sort()

graph = [[] for i in range(N)]
for i in ab_list:
    graph[i[0]-1].append(i[1])
    graph[i[1]-1].append(i[0])
    
ans = []
ten_col = [[] for i in range(N)]
def dfs(start,now,color):
    ten_col[now-1]=[color]
    for i in graph[now-1]:
        if i == start:
            pass
        else:
            new_col = 1
            while True:
                if new_col not in ten_col[now-1]:
                    ten_col[now-1].append(new_col)
                    ans.append(new_col)
                    break
                else:
                    new_col += 1
            dfs(now,i,new_col)
            
dfs(-1,1,0)
print(max(ans))
for i in ans:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)