Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
T = [[]for i in range(N)]
A = []
D = [[0]*N for i in range(N)]
for i in range(N-1):
    a,b = map(lambda x:int(x)-1,input().split())
    T[a].append(b)
    T[b].append(a)
    A.append((a,b))
K = 0
for t in T:
    K = max(K,len(t))
print(K)
Q = deque([(0,-1,0)])
while Q:
    q = Q.popleft()
    v,p,k = q[0],q[1],q[2]
    ck = 1
    for c in T[v]:
        if ck==k:ck+=1
        if c!=p:
            if len(T[c])!=1:
                Q.append((c,v,ck))
            D[c][v] = ck
            D[v][c] = ck
            ck+=1
for a in A:
    print(D[a[0]][a[1]])

Fixed submission:
from collections import deque
N = int(input())
ab = [list(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]
T = [[] for i in range(N)]
for a,b in ab:
    T[a].append(b)
q = deque([0])
color = [0]*N
while q:
    x = q.popleft()
    c = 1
    for y in T[x]:
        if c==color[x]:
            c+=1
        color[y] = c
        c+=1
        q.append(y)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = [[]for i in range(N)]
A = []
D = [[0]*N for i in range(N)]
for i in range(N-1):
    a,b = map(lambda x:int(x)-1,input().split())
    T[a].append(b)
    T[b].append(a)
    A.append((a,b))
K = 0
for t in T:
    K = max(K,len(t))
print(K)
Q = [(0,-1,0)]
while Q:
    q = Q.pop(-1)
    v,p,k = q[0],q[1],q[2]
    ck = 1
    for c in T[v]:
        if ck==k:ck+=1
        if c!=p:
            if len(T[c])!=1:
                Q.append((c,v,ck))
            D[c][v] = ck
            D[v][c] = ck
            ck+=1
for a in A:
    print(D[a[0]][a[1]])

Fixed submission:
from collections import deque
N = int(input())
ab = [list(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]
T = [[] for i in range(N)]
for a,b in ab:
    T[a].append(b)
q = deque([0])
color = [0]*N
while q:
    x = q.popleft()
    c = 1
    for y in T[x]:
        if c==color[x]:
            c+=1
        color[y] = c
        c+=1
        q.append(y)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = [[]for i in range(N)]
A = []
D = [[0]*N for i in range(N)]
for i in range(N-1):
    a,b = map(lambda x:int(x)-1,input().split())
    T[a].append(b)
    T[b].append(a)
    A.append((a,b))
K = 0
for t in T:
    K = max(K,len(t))
print(K)
Q = [(0,-1,0)]
while Q:
    q = Q.pop(-1)
    v,p,k = q[0],q[1],q[2]
    ck = 1
    for c in T[v]:
        if ck==k:ck+=1
        if c!=p:
            Q.append((c,v,ck))
            D[c][v] = ck
            D[v][c] = ck
            ck+=1
for a in A:
    print(D[a[0]][a[1]])

Fixed submission:
from collections import deque
N = int(input())
ab = [list(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]
T = [[] for i in range(N)]
for a,b in ab:
    T[a].append(b)
q = deque([0])
color = [0]*N
while q:
    x = q.popleft()
    c = 1
    for y in T[x]:
        if c==color[x]:
            c+=1
        color[y] = c
        c+=1
        q.append(y)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
N = int(input())

G = [[] for i in range(N+1)]
D = [0]*(N+1)
E = [[0]*(N+1) for i in range(N+1)]
Q = []
for i in range(N-1):
    a,b = map(int,input().split())
    Q.append((a,b))
    G[a].append(b)
    G[b].append(a)
    D[a]+=1
    D[b]+=1

mod = max(D)
print(mod)
def dfs(v,p):
    global G,D,E
    k = E[v][p]
    for c in G[v]:
        if c==p:continue
        k = (k+1)%mod
        E[v][c] = k
        E[c][v] = k
        dfs(c,v)
dfs(1,0)
for q in Q:print(E[q[0]][q[1]]+1)

Fixed submission:
from collections import deque
N = int(input())
ab = [list(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]
T = [[] for i in range(N)]
for a,b in ab:
    T[a].append(b)
q = deque([0])
color = [0]*N
while q:
    x = q.popleft()
    c = 1
    for y in T[x]:
        if c==color[x]:
            c+=1
        color[y] = c
        c+=1
        q.append(y)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
N = int(input())

G = [[] for i in range(N+1)]
D = [0]*(N+1)
E = [[0]*(N+1) for i in range(N+1)]
Q = []
for i in range(N-1):
    a,b = map(int,input().split())
    Q.append((a,b))
    G[a].append(b)
    G[b].append(a)
    D[a]+=1
    D[b]+=1

mod = max(D)
print(mod)
def dfs(v,p):
    global G,D,E
    k = E[v][p]
    for c in G[v]:
        if c==p:continue
        k = (k+1)%mod
        E[v][c] = k
        E[c][v] = k
        dfs(c,v)
dfs(1,0)
for q in Q:print(E[q[0]][q[1]]+1)

Fixed submission:
from collections import deque
N = int(input())
ab = [list(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]
T = [[] for i in range(N)]
for a,b in ab:
    T[a].append(b)
q = deque([0])
color = [0]*N
while q:
    x = q.popleft()
    c = 1
    for y in T[x]:
        if c==color[x]:
            c+=1
        color[y] = c
        c+=1
        q.append(y)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])