import sys

sys.setrecursionlimit(1000000)



n = int(eval(input()))

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

for i in range(n - 1):

    a, b = [int(i)-1 for i in input().split()]

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

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

re = [False] * n

ed = [0]*(n-1)





def c(i=0, used=-1):

    global re, ed

    if re[i]:

        return 0

    re[i] = True

    k = 1

    for j in ab[i]:

        if re[j[0]]:

            continue

        if k == used:

            k += 1

        ed[j[1]] = k

        c(j[0], k)

        k += 1





c()

print((max(ed)))

print((" ".join([str(i) for i in ed])))
import sys

sys.setrecursionlimit(1000000)

def input():

    return sys.stdin.readline()

n = int(eval(input()))

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

for j in range(n - 1):

    a, b = [int(i)-1 for i in input().split()]

    e[a].append((b, j))

    e[b].append((a, j))



co = [0]*(n-1)





def dfs(i=0, r=-1, dis=-1):

    global co

    c = 1

    for j in e[i]:

        if j[0] == r:

            continue

        if c == dis:

            c += 1

        co[j[1]] = c

        dfs(j[0], i, c)

        c += 1





dfs()



print((max(co)))

for i in co:

    print(i)

import sys

sys.setrecursionlimit(1000000)
n = int(eval(input()))
ab = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    ab[a].append([b, i])
    ab[b].append([a, i])
re = [False] * n
ed = [0] * (n - 1)


def c(i=0, used=-1):
    global re, ed
    if re[i]:
        return 0
    re[i] = True
    k = 1
    for j in ab[i]:
        if re[j[0]]:
            continue
        if k == used:
            k += 1
        ed[j[1]] = k
        c(j[0], k)
        k += 1


c()
print((max(ed)))
print((" ".join([str(i) for i in ed])))

import sys

sys.setrecursionlimit(1000000)


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


n = int(eval(input()))
e = [[] for _ in range(n)]
for j in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append((b, j))
    e[b].append((a, j))
co = [0] * (n - 1)


def dfs(i=0, r=-1, dis=-1):
    global co
    c = 1
    for j in e[i]:
        if j[0] == r:
            continue
        if c == dis:
            c += 1
        co[j[1]] = c
        dfs(j[0], i, c)
        c += 1


dfs()
print((max(co)))
for i in co:
    print(i)

-n = int(eval(input())) -ab = [[] for _ in range(n)] -for i in range(n - 1): -    a, b = [int(i) - 1 for i in input().split()] -    ab[a].append([b, i]) -    ab[b].append([a, i]) -re = [False] * n -ed = [0] * (n - 1) -def c(i=0, used=-1): -    global re, ed -    if re[i]: -        return 0 -    re[i] = True -    k = 1 -    for j in ab[i]: -        if re[j[0]]: -            continue -        if k == used: -            k += 1 -        ed[j[1]] = k -        c(j[0], k) -        k += 1 +def input(): +    return sys.stdin.readline() -c() -print((max(ed))) -print((" ".join([str(i) for i in ed]))) +n = int(eval(input())) +e = [[] for _ in range(n)] +for j in range(n - 1): +    a, b = [int(i) - 1 for i in input().split()] +    e[a].append((b, j)) +    e[b].append((a, j)) +co = [0] * (n - 1) + + +def dfs(i=0, r=-1, dis=-1): +    global co +    c = 1 +    for j in e[i]: +        if j[0] == r: +            continue +        if c == dis: +            c += 1 +        co[j[1]] = c +        dfs(j[0], i, c) +        c += 1 + + +dfs() +print((max(co))) +for i in co: +    print(i)