import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 6)





n = int(input())

g = [[] for _ in range(n)]

for i in range(n-1):

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

    a, b = a - 1, b - 1

    g[a].append((b, i))

    g[b].append((a, i))

ans = [0] * (n-1)





def dfs(u, c=-1, p=-1):

    k = 1

    for v, i in g[u]:

        if v == p: continue

        if k == c: k += 1

        ans[i] = k

        k += 1

        dfs(v, ans[i], u)





dfs(0)

print(max(ans))

print(*ans, sep='\n')

from collections import deque

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 6)





def main():

    N = int(eval(input()))

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

    edge_order = []

    for i in range(N-1):

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

        a, b = a - 1, b - 1

        g[a].append((i, b))

        edge_order.append(b)

    # 頂点1からBFS

    queue = deque([0])

    color = [0] * N

    while queue:

        v = queue.popleft()

        c = 1  # 色の初期値は一からスタート

        for i, u in g[v]:

            if c == color[v]:  # 親と色が同じ時

                c += 1

            color[u] = c

            c += 1

            queue.append(u)

    print((max(color)))

    for i in edge_order:

        print((color[i]))

if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    g[a].append((b, i))
    g[b].append((a, i))
ans = [0] * (n - 1)


def dfs(u, c=-1, p=-1):
    k = 1
    for v, i in g[u]:
        if v == p:
            continue
        if k == c:
            k += 1
        ans[i] = k
        k += 1
        dfs(v, ans[i], u)


dfs(0)
print(max(ans))
print(*ans, sep="\n")

from collections import deque
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    N = int(eval(input()))
    g = [[] for _ in range(N)]
    edge_order = []
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a, b = a - 1, b - 1
        g[a].append((i, b))
        edge_order.append(b)
    # 頂点1からBFS
    queue = deque([0])
    color = [0] * N
    while queue:
        v = queue.popleft()
        c = 1  # 色の初期値は一からスタート
        for i, u in g[v]:
            if c == color[v]:  # 親と色が同じ時
                c += 1
            color[u] = c
            c += 1
            queue.append(u)
    print((max(color)))
    for i in edge_order:
        print((color[i]))


if __name__ == "__main__":
    main()

+from collections import deque -n = int(input()) -g = [[] for _ in range(n)] -for i in range(n - 1): -    a, b = map(int, input().split()) -    a, b = a - 1, b - 1 -    g[a].append((b, i)) -    g[b].append((a, i)) -ans = [0] * (n - 1) -def dfs(u, c=-1, p=-1): -    k = 1 -    for v, i in g[u]: -        if v == p: -            continue -        if k == c: -            k += 1 -        ans[i] = k -        k += 1 -        dfs(v, ans[i], u) +def main(): +    N = int(eval(input())) +    g = [[] for _ in range(N)] +    edge_order = [] +    for i in range(N - 1): +        a, b = list(map(int, input().split())) +        a, b = a - 1, b - 1 +        g[a].append((i, b)) +        edge_order.append(b) +    # 頂点1からBFS +    queue = deque([0]) +    color = [0] * N +    while queue: +        v = queue.popleft() +        c = 1  # 色の初期値は一からスタート +        for i, u in g[v]: +            if c == color[v]:  # 親と色が同じ時 +                c += 1 +            color[u] = c +            c += 1 +            queue.append(u) +    print((max(color))) +    for i in edge_order: +        print((color[i])) -dfs(0) -print(max(ans)) -print(*ans, sep="\n") +if __name__ == "__main__": +    main()