from collections import deque



def main():

    N = int(eval(input()))

    path = [[] for _ in range(N)]

    ab = []

    ans = {}

    visited = [False] * N

    visited[0] = True

    for _ in range(N-1):

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

        path[a-1].append(b-1)

        path[b-1].append(a-1)

        ab.append((a-1, b-1))

    

    que = deque([(0, 0)])

    while que:

        k = 1

        # k = 0

        pre, c = que.popleft()

        for next_node in path[pre]:

            if visited[next_node]:

                continue

            

            if c == k:

                k += 1

            visited[next_node] = True

            ans[(pre, next_node)] = k

            que.append((next_node, k))

            k += 1

            



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

    for key in ab:

        print((ans[key]))



if __name__ == '__main__':

    main()
from collections import deque



def main():

    N = int(eval(input()))

    path = [[] for _ in range(N)]

    ab = []

    ans = {}

    visited = [False] * N

    visited[0] = True

    for _ in range(N-1):

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

        path[a-1].append(b-1)

        # path[b-1].append(a-1)

        ab.append((a-1, b-1))

    

    que = deque([(0, 0)])

    while que:

        k = 1

        pre, c = que.popleft()

        for next_node in path[pre]:

            if visited[next_node]:

                continue

            

            if c == k:

                k += 1

            visited[next_node] = True

            ans[(pre, next_node)] = k

            que.append((next_node, k))

            k += 1

            



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

    for key in ab:

        print((ans[key]))



if __name__ == '__main__':

    main()
from collections import deque


def main():
    N = int(eval(input()))
    path = [[] for _ in range(N)]
    ab = []
    ans = {}
    visited = [False] * N
    visited[0] = True
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        path[a - 1].append(b - 1)
        path[b - 1].append(a - 1)
        ab.append((a - 1, b - 1))
    que = deque([(0, 0)])
    while que:
        k = 1
        # k = 0
        pre, c = que.popleft()
        for next_node in path[pre]:
            if visited[next_node]:
                continue
            if c == k:
                k += 1
            visited[next_node] = True
            ans[(pre, next_node)] = k
            que.append((next_node, k))
            k += 1
    print((max(ans.values())))
    for key in ab:
        print((ans[key]))


if __name__ == "__main__":
    main()

from collections import deque


def main():
    N = int(eval(input()))
    path = [[] for _ in range(N)]
    ab = []
    ans = {}
    visited = [False] * N
    visited[0] = True
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        path[a - 1].append(b - 1)
        # path[b-1].append(a-1)
        ab.append((a - 1, b - 1))
    que = deque([(0, 0)])
    while que:
        k = 1
        pre, c = que.popleft()
        for next_node in path[pre]:
            if visited[next_node]:
                continue
            if c == k:
                k += 1
            visited[next_node] = True
            ans[(pre, next_node)] = k
            que.append((next_node, k))
            k += 1
    print((max(ans.values())))
    for key in ab:
        print((ans[key]))


if __name__ == "__main__":
    main()

-        path[b - 1].append(a - 1) +        # path[b-1].append(a-1) -        # k = 0