Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    y = G[x]
    k = D[x] + 1
    if k > K:
        k -= K
    while y:
        z = y.pop(0)
        if z not in list:
            if z not in sumi:
                list.append(z)
                d[(x,z)] = k
                D[z] = k
                k += 1
                if k > K:
                    k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])


Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    y = G[x]
    k = D[x] + 1
    if k > K:
        k -= K
    while y:
        z = y.pop(0)
        if z not in list:
            if z not in sumi:
                list.append(z)
                d[(x,z)] = k
                D[z] = k
                k += 1
                if k > K:
                    k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
C = [[i for i in range(1,K+1)] for j in range(N+1)]
import copy 
w = copy.deepcopy(W)
d = {}
w.sort()
for i in range(N-1):
    a,b = w[i]
    x = C[a].pop(0)
    C[b].remove(x)
    d[a+b*N] = x
for i in range(N-1):
    a,b = W[i]
    print(d[a+b*N])

Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
C = [[i for i in range(1,K+1)] for j in range(N+1)]
import copy 
w = copy.deepcopy(W)
d = {}
w.sort()
for i in range(N-1):
    a,b = w[i]
    x = C[a].pop(0)
    C[b].remove(x)
    d[a+b*N] = x
for i in range(N-1):
    a,b = W[i]
    print(d[a+b*N])

Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Buggy python submission (verdict: Runtime Error):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
C = [[i for i in range(1,K+1)] for j in range(N+1)]

for i in range(N-1):
    a,b = W[i]
    x = C[a].pop(0)
    C[b].remove(x)
    print(x)

Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
C = [[i for i in range(1,K+1)] for j in range(N+1)]
import copy 
w = copy.deepcopy(W)
d = [[0 for i in range(N+1)] for j in range(N+1)]
w.sort()
for i in range(N-1):
    a,b = w[i]
    x = C[a].pop(0)
    C[b].remove(x)
    d[a][b] = x
for i in range(N-1):
    a,b = W[i]
    print(d[a][b])


Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
C = [[i for i in range(1,K+1)] for j in range(N+1)]
import copy 
w = copy.deepcopy(W)
d = [[0 for i in range(N+1)] for j in range(N+1)]
w.sort()
for i in range(N-1):
    a,b = w[i]
    x = C[a].pop(0)
    C[b].remove(x)
    d[a][b] = x
for i in range(N-1):
    a,b = W[i]
    print(d[a][b])


Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])