import sys

from collections import deque

def input(): return sys.stdin.readline().rstrip()



def main():

    N = int(eval(input()))

    ab = [tuple(map(int, input().split())) for _ in range(N-1)]



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

    for a, b in ab:

        graph[a].add(b)

        graph[b].add(a)



    d = deque()

    d.append(1)



    ans = [-1] * (N+1)



    parent = [-1] * (N+1)

    parent[1] = 1



    while d:

        p = d.popleft()

        c = 0

        for g in graph[p]:

            if parent[g] > 0 or g == parent[g]:

                continue

            c += 1

            if c == ans[p]:

                c += 1

            ans[g] = c



            parent[g] = p

            d.append(g)



    print((max(ans)))

    for _, b in ab:

        print((ans[b]))



if __name__ == '__main__':

    main()

# https://atcoder.jp/contests/abc102/tasks/arc100_a

import sys

from collections import deque

def input(): return sys.stdin.readline().rstrip()



def main():

    N = int(eval(input()))

    ab = [tuple(map(int, input().split())) for _ in range(N-1)]



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

    for a, b in ab:

        graph[a].add(b)

        graph[b].add(a)



    d = deque()

    d.append(1)



    ans = [-1] * (N+1)



    parent = [-1] * (N+1)

    parent[1] = 1



    while d:

        p = d.popleft()

        c = 0

        for g in graph[p]:

            if parent[g] > 0 or g == parent[g]:

                continue

            c += 1

            if c == ans[p]:

                c += 1

            ans[g] = c



            parent[g] = p

            d.append(g)



    print((max(ans)))

    print(('\n'.join([str(ans[b]) for _, b in ab])))



if __name__ == '__main__':

    main()

import sys
from collections import deque


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(eval(input()))
    ab = [tuple(map(int, input().split())) for _ in range(N - 1)]
    graph = [set() for _ in range(N + 1)]
    for a, b in ab:
        graph[a].add(b)
        graph[b].add(a)
    d = deque()
    d.append(1)
    ans = [-1] * (N + 1)
    parent = [-1] * (N + 1)
    parent[1] = 1
    while d:
        p = d.popleft()
        c = 0
        for g in graph[p]:
            if parent[g] > 0 or g == parent[g]:
                continue
            c += 1
            if c == ans[p]:
                c += 1
            ans[g] = c
            parent[g] = p
            d.append(g)
    print((max(ans)))
    for _, b in ab:
        print((ans[b]))


if __name__ == "__main__":
    main()

# https://atcoder.jp/contests/abc102/tasks/arc100_a
import sys
from collections import deque


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(eval(input()))
    ab = [tuple(map(int, input().split())) for _ in range(N - 1)]
    graph = [set() for _ in range(N + 1)]
    for a, b in ab:
        graph[a].add(b)
        graph[b].add(a)
    d = deque()
    d.append(1)
    ans = [-1] * (N + 1)
    parent = [-1] * (N + 1)
    parent[1] = 1
    while d:
        p = d.popleft()
        c = 0
        for g in graph[p]:
            if parent[g] > 0 or g == parent[g]:
                continue
            c += 1
            if c == ans[p]:
                c += 1
            ans[g] = c
            parent[g] = p
            d.append(g)
    print((max(ans)))
    print(("\n".join([str(ans[b]) for _, b in ab])))


if __name__ == "__main__":
    main()

+# https://atcoder.jp/contests/abc102/tasks/arc100_a -    for _, b in ab: -        print((ans[b])) +    print(("\n".join([str(ans[b]) for _, b in ab])))