### BUGGY CODE ###

#!/usr/bin/env pypy3
 
import sys
from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()

 
def main():
    input = sys.stdin.readline      # 改行文字が残ることに注意
    def ii():  return int(input())
            

    def bfs_tree_traverse(start):
        paths = deque([[start]])
        max_branch = 0
        pp = paths.popleft    # 定数倍高速化への道のり
        pa = paths.append    # 定数倍高速化への道のり
        while paths:
            # current_path = paths.popleft()
            current_path = pp()    # 定数倍高速化への道のり
            u = current_path[-1]
            previous = current_path[-2] if len(current_path)>=2 else -1
            previous_color = color[current_path[-2]][u] if len(current_path)>=2 else 0
            count = 0    # 現在の頂点 u から伸びるリンクの数を数える
            current_color = 0
            for v in adj[u]:
                count += 1    # 親へのリンクも含めて数えている
                if v != previous:
                    # tmp = current_path[:]
                    tmp = current_path[-1:]    # 定数倍高速化への道のり
                    tmp.append(v)
                    pa(tmp)    # 定数倍高速化への道のり
                    current_color += 1
                    if current_color == previous_color:
                        current_color += 1
                    color[u][v] = current_color
                    # color[v][u] = current_color    # 定数倍高速化への道のり
            max_branch = max(max_branch, count)
        return max_branch
 
 
    n = ii()
    adj = [[] for _ in range(n)]
 
    # L = [tuple(map(lambda x: int(x)-1, input().rstrip().split())) for _ in range(n-1)]    # 定数倍高速化への道のり
    L = [None] * (n-1)   # 定数倍高速化への道のり
    for i in range(n-1):
        L[i] = tuple(map(lambda x: int(x)-1, input().rstrip().split()))
 
    for pair in L:
        a, b = pair
        adj[a].append(b)
        adj[b].append(a)
    
    color = [[None] * n for _ in range(n)]
    
    print(bfs_tree_traverse(0))
    for pair in L:
        a, b = pair
        print(color[a][b])
 
if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3
 
import sys
from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()


def main():
    input = sys.stdin.readline      # 改行文字が残ることに注意
    def ii():  return int(input())
            

    def bfs_tree_traverse(root):
        ' root から BFS し条件を満たすように彩色していく。各辺の色情報を color に記載。最後に使用した色の数を返す。'
        paths = deque([root])
        max_branch = 0
        while len(paths) != 0:
            edge_color = 0
            current = paths.popleft()
            parent_edge_color = color[current]
            for v in adj[current]:
                paths.append(v)
                edge_color += 1
                if edge_color == parent_edge_color:
                    edge_color += 1
                color[v] = edge_color
                max_branch = max(max_branch, edge_color)
        return max_branch
        
 
    n = ii()
    # 各辺の両端の頂点 index を保存したペア (tuple) の list
    L = [tuple(map(lambda x: int(x)-1, input().rstrip().split())) for _ in range(n-1)]
    # 隣接リスト 親->子のみリンクをはれば十分
    adj = [[] for _ in range(n)]
    for pair in L:
        a, b = pair
        adj[a].append(b)
    # 各辺の子供の index と色情報 (int) の対応記載される隣接行列 
    color = [0] * n
    
    print(bfs_tree_traverse(0))
    for pair in L:
        _, b = pair
        print(color[b])
 
if __name__ == "__main__":
    main()