### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline
    
def bfs(v, N, G, E):
    visited = [0]*N
    queue = deque()
    new_color = 1
    used_color = set()
    num_used_color = 0
    node2colors = [set() for _ in range(N)]
    queue.append(v)
    visited[v] = 1
    while queue:
        q = queue.popleft()
        # print("q",q)
        num_color_from_q = 0
        while G[q]:
            nex = G[q].popleft()
            if visited[nex]:
                continue
            visited[nex] = 1
            rest = num_used_color - num_color_from_q
            # print(rest)
            if rest > 0:
                usd_c = used_color - node2colors[q]
                if usd_c:
                    # print(used_color, node2colors[q])
                    usd_c = min(usd_c)
                    E[(q, nex)][1] = usd_c
                    node2colors[q].add(usd_c)
                    num_color_from_q += 1
                    node2colors[nex].add(usd_c)
                else:
                    # print(num_used_color, num_color_from_q)
                    new_c = new_color
                    new_color += 1
                    num_used_color += 1
                    E[(q, nex)][1] = new_c
                    node2colors[q].add(new_c)
                    num_color_from_q += 1
                    node2colors[nex].add(new_c)
                    used_color.add(new_c)
                    
            else:
                new_c = new_color
                new_color += 1
                num_used_color += 1
                E[(q, nex)][1] = new_c
                node2colors[q].add(new_c)
                num_color_from_q += 1
                node2colors[nex].add(new_c)
                used_color.add(new_c)
        
            queue.append(nex)
    return num_used_color

def main():
    N = int(input())
    G = [deque() for _ in range(N)]
    E = dict() # (a, b) -> [idx, color]
    for i in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        G[a].append(b)
        G[b].append(a)
        E[(a, b)] = [i, 0]
    K = bfs(0, N, G, E)
    # ans_list = [value for value in E.values()]
    print(K)
    for value in E.values():
        print(value[1])
main()

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
    
def bfs(v, N, G, E):
    visited = [0]*N
    queue = deque()
    K = -1
    node2color = [-1 for _ in range(N)]
    queue.append(v)
    visited[v] = 1
    while queue:
        q = queue.popleft()
        color = 0
        for nex in G[q]:
            if visited[nex]:
                continue
            visited[nex] = 1
            color += 1
            if color == node2color[q]:
                color += 1
            
            node2color[nex] = color
            E[(min(q, nex), max(q, nex))] = color
            queue.append(nex)
        K = max(K, color)
    return K

def main():
    N = int(input())
    G = [deque() for _ in range(N)]
    E = dict() # (a, b) -> [idx, color]
    for i in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        G[a].append(b)
        G[b].append(a)
        E[(a, b)] = 0
    K = bfs(0, N, G, E)
    # ans_list = [value for value in E.values()]
    print(K)
    for value in E.values():
        print(value)
main()