def solve():

    from collections import deque

    import sys



    input = sys.stdin.readline



    n = int(input())



    g = tuple(set() for _ in range(n))

    for idx in range(n - 1):

        a, b = (int(x) - 1 for x in input().split())

        g[a].add((b, idx))

        g[b].add((a, idx))



    q = deque()

    q.append((0, -1, -1))



    e = [-1] * n  # e[-1]は使わない

    used = [False] * n

    used[0] = True

    while q:

        v, v_idx, prev_color = q.popleft()

        curr = 1 if prev_color != 1 else 2

        for u, u_idx in g[v]:

            if used[u]:

                continue

            used[u] = True

            e[u_idx] = curr

            q.append((u, u_idx, curr))

            curr += 1

            if curr == prev_color:

                curr += 1



    ret = e[:-1]

    return len(set(ret)), ret





l, ret = solve()

print(l)

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

def main():

    from collections import deque

    import sys

    input = sys.stdin.readline



    N = int(input())



    g = tuple(set() for _ in range(N))

    for i in range(N - 1):

        a, b = (int(x) - 1 for x in input().split())

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

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



    dq = deque()

    dq.append([0, -1])

    color = [-1] * (N - 1)

    while dq:

        v, skip = dq.popleft()

        color_to_use = 1

        for u, i in g[v]:

            if ~color[i]: continue

            if color_to_use == skip:

                color_to_use += 1

            color[i] = color_to_use

            dq.append((u, color_to_use))

            color_to_use += 1



    print(max(color))

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





if __name__ == '__main__':

    main()

def solve():
    from collections import deque
    import sys

    input = sys.stdin.readline
    n = int(input())
    g = tuple(set() for _ in range(n))
    for idx in range(n - 1):
        a, b = (int(x) - 1 for x in input().split())
        g[a].add((b, idx))
        g[b].add((a, idx))
    q = deque()
    q.append((0, -1, -1))
    e = [-1] * n  # e[-1]は使わない
    used = [False] * n
    used[0] = True
    while q:
        v, v_idx, prev_color = q.popleft()
        curr = 1 if prev_color != 1 else 2
        for u, u_idx in g[v]:
            if used[u]:
                continue
            used[u] = True
            e[u_idx] = curr
            q.append((u, u_idx, curr))
            curr += 1
            if curr == prev_color:
                curr += 1
    ret = e[:-1]
    return len(set(ret)), ret


l, ret = solve()
print(l)
print(*ret, sep="\n")

def main():
    from collections import deque
    import sys

    input = sys.stdin.readline
    N = int(input())
    g = tuple(set() for _ in range(N))
    for i in range(N - 1):
        a, b = (int(x) - 1 for x in input().split())
        g[a].add((b, i))
        g[b].add((a, i))
    dq = deque()
    dq.append([0, -1])
    color = [-1] * (N - 1)
    while dq:
        v, skip = dq.popleft()
        color_to_use = 1
        for u, i in g[v]:
            if ~color[i]:
                continue
            if color_to_use == skip:
                color_to_use += 1
            color[i] = color_to_use
            dq.append((u, color_to_use))
            color_to_use += 1
    print(max(color))
    print(*color, sep="\n")


if __name__ == "__main__":
    main()

-def solve(): +def main(): -    n = int(input()) -    g = tuple(set() for _ in range(n)) -    for idx in range(n - 1): +    N = int(input()) +    g = tuple(set() for _ in range(N)) +    for i in range(N - 1): -        g[a].add((b, idx)) -        g[b].add((a, idx)) -    q = deque() -    q.append((0, -1, -1)) -    e = [-1] * n  # e[-1]は使わない -    used = [False] * n -    used[0] = True -    while q: -        v, v_idx, prev_color = q.popleft() -        curr = 1 if prev_color != 1 else 2 -        for u, u_idx in g[v]: -            if used[u]: +        g[a].add((b, i)) +        g[b].add((a, i)) +    dq = deque() +    dq.append([0, -1]) +    color = [-1] * (N - 1) +    while dq: +        v, skip = dq.popleft() +        color_to_use = 1 +        for u, i in g[v]: +            if ~color[i]: -            used[u] = True -            e[u_idx] = curr -            q.append((u, u_idx, curr)) -            curr += 1 -            if curr == prev_color: -                curr += 1 -    ret = e[:-1] -    return len(set(ret)), ret +            if color_to_use == skip: +                color_to_use += 1 +            color[i] = color_to_use +            dq.append((u, color_to_use)) +            color_to_use += 1 +    print(max(color)) +    print(*color, sep="\n") -l, ret = solve() -print(l) -print(*ret, sep="\n") +if __name__ == "__main__": +    main()