import sys

input = sys.stdin.readline

from collections import deque



def readlines(n):

    for _ in range(n):

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

        yield a, b



def main():

    N = int(eval(input()))

    edges = list(readlines(N-1))

    tree = {i:[] for i in range(N)}

    for a, b in edges:

        tree[a].append(b)



    ans = {}

    frontier = deque([(1,0)])

    while frontier:

        u, prev_color = frontier.pop()

        if tree.get(u) is None:

            continue

        for i, v in enumerate(tree[u], 1):

            color = i if i != prev_color else len(tree[u])+1

            ans[u, v] = color

            frontier.appendleft((v, color))



    print((max(ans.values())))

    for u,v in edges:

        print((ans[u,v]))





    

main()
import sys

input = sys.stdin.readline

from collections import deque



def main():

    N = int(eval(input()))

    tree = {i:[] for i in range(N)}

    edges = []

    for _ in range(N-1):

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

        edges.append((a, b))

        tree[a].append(b)



    ans = {}

    frontier = deque([(1,0)])

    while frontier:

        u, prev_color = frontier.pop()

        if tree.get(u) is None:

            continue

        for i, v in enumerate(tree[u], 1):

            color = i if i != prev_color else len(tree[u])+1

            ans[u, v] = color

            frontier.appendleft((v, color))



    print((max(ans.values())))

    for edge in edges:

        print((ans[edge]))





    

main()
import sys

input = sys.stdin.readline
from collections import deque


def readlines(n):
    for _ in range(n):
        a, b = list(map(int, input().split()))
        yield a, b


def main():
    N = int(eval(input()))
    edges = list(readlines(N - 1))
    tree = {i: [] for i in range(N)}
    for a, b in edges:
        tree[a].append(b)
    ans = {}
    frontier = deque([(1, 0)])
    while frontier:
        u, prev_color = frontier.pop()
        if tree.get(u) is None:
            continue
        for i, v in enumerate(tree[u], 1):
            color = i if i != prev_color else len(tree[u]) + 1
            ans[u, v] = color
            frontier.appendleft((v, color))
    print((max(ans.values())))
    for u, v in edges:
        print((ans[u, v]))


main()

import sys

input = sys.stdin.readline
from collections import deque


def main():
    N = int(eval(input()))
    tree = {i: [] for i in range(N)}
    edges = []
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        edges.append((a, b))
        tree[a].append(b)
    ans = {}
    frontier = deque([(1, 0)])
    while frontier:
        u, prev_color = frontier.pop()
        if tree.get(u) is None:
            continue
        for i, v in enumerate(tree[u], 1):
            color = i if i != prev_color else len(tree[u]) + 1
            ans[u, v] = color
            frontier.appendleft((v, color))
    print((max(ans.values())))
    for edge in edges:
        print((ans[edge]))


main()

-def readlines(n): -    for _ in range(n): -        a, b = list(map(int, input().split())) -        yield a, b - - -    edges = list(readlines(N - 1)) -    for a, b in edges: +    edges = [] +    for _ in range(N - 1): +        a, b = list(map(int, input().split())) +        edges.append((a, b)) -    for u, v in edges: -        print((ans[u, v])) +    for edge in edges: +        print((ans[edge]))