from collections import deque

def main():

    N = int(eval(input()))

    # 辺の集合を隣接リストとして入力

    E = [[] for i in range(N+1)]

    edge_order = []

    for i in range(N-1):

        a,b = list(map(int, input().split()))

        E[a].append(b)

        edge_order.append(b)

    

    # 頂点1から幅優先探索

    queue = deque([1])

    color = [0] * (N+1) 

    while queue:

        V = queue.popleft()

        c = 1

        for i in E[V]:

            if c == color[V]:

                c += 1

            color[i] = c

            c += 1

            queue.append(i)



    print((max(color)))

    for i in edge_order:

        print((color[i]))





if __name__ == "__main__":

    main()

import sys

from collections import deque

read = sys.stdin.read



def main():

    N, *ab = list(map(int, read().split()))

    E = [[] for _ in range(N + 1)]

    edge_order = []

    

    for a, b in zip(*[iter(ab)] * 2):

        E[a].append(b)

        edge_order.append(b)

    

    # 頂点1から幅優先探索

    queue = deque([1])

    color = [0] * (N+1) 

    while queue:

        V = queue.popleft()

        c = 1

        for i in E[V]:

            if c == color[V]:

                c += 1

            color[i] = c

            c += 1

            queue.append(i)



    print((max(color)))

    for i in edge_order:

        print((color[i]))





if __name__ == "__main__":

    main()

from collections import deque


def main():
    N = int(eval(input()))
    # 辺の集合を隣接リストとして入力
    E = [[] for i in range(N + 1)]
    edge_order = []
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        E[a].append(b)
        edge_order.append(b)
    # 頂点1から幅優先探索
    queue = deque([1])
    color = [0] * (N + 1)
    while queue:
        V = queue.popleft()
        c = 1
        for i in E[V]:
            if c == color[V]:
                c += 1
            color[i] = c
            c += 1
            queue.append(i)
    print((max(color)))
    for i in edge_order:
        print((color[i]))


if __name__ == "__main__":
    main()

import sys
from collections import deque

read = sys.stdin.read


def main():
    N, *ab = list(map(int, read().split()))
    E = [[] for _ in range(N + 1)]
    edge_order = []
    for a, b in zip(*[iter(ab)] * 2):
        E[a].append(b)
        edge_order.append(b)
    # 頂点1から幅優先探索
    queue = deque([1])
    color = [0] * (N + 1)
    while queue:
        V = queue.popleft()
        c = 1
        for i in E[V]:
            if c == color[V]:
                c += 1
            color[i] = c
            c += 1
            queue.append(i)
    print((max(color)))
    for i in edge_order:
        print((color[i]))


if __name__ == "__main__":
    main()

+import sys + +read = sys.stdin.read -    N = int(eval(input())) -    # 辺の集合を隣接リストとして入力 -    E = [[] for i in range(N + 1)] +    N, *ab = list(map(int, read().split())) +    E = [[] for _ in range(N + 1)] -    for i in range(N - 1): -        a, b = list(map(int, input().split())) +    for a, b in zip(*[iter(ab)] * 2):