# -*- coding: utf-8 -*-

import sys

import queue

input = sys.stdin.readline

def ii(): return int(input().rstrip())

def mi(): return map(int, input().rstrip().split())

def lmi(): return list(map(int, input().rstrip().split()))

def fi(): return float(input())

def mfi(): return map(float, input().rstrip().split())

def lmfi(): return list(map(float, input().rstrip().split()))

def li(): return list(input().rstrip())

def exit(*arg): print(*arg); sys.exit()

# template





def main():

    n = ii()

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

    for i in range(n - 1):

        a, b = mi()

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

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

    color = max([len(g[i]) for i in range(n)])

    print(color)

    q = queue.Queue()

    ans = [-1 for i in range(n - 1)]

    idx = 0

    q.put((0, 0))

    while not q.empty():

        t, idx = q.get()

        for e in g[t]:

            if ans[e[1]] != -1:

                continue

            idx += 1

            ans[e[1]] = idx

            q.put((e[0], idx))

    print(*map(lambda x: x % color + 1, ans), sep="\n")

    return





if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-

import sys

import collections

input = sys.stdin.readline

def ii(): return int(input().rstrip())

def mi(): return map(int, input().rstrip().split())

def lmi(): return list(map(int, input().rstrip().split()))

def fi(): return float(input().rstrip())

def mfi(): return map(float, input().rstrip().split())

def lmfi(): return list(map(float, input().rstrip().split()))

def li(): return list(input().rstrip())

def exit(*arg): print(*arg); sys.exit()

# template





def main():

    n = ii()

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

    for i in range(n - 1):

        a, b = mi()

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

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

    color = max([len(g[i]) for i in range(n)])

    print(color)

    q = collections.deque()

    ans = [-1 for i in range(n - 1)]

    idx = 0

    q.append((0, 0))

    while len(q):

        t, idx = q.popleft()

        for e in g[t]:

            if ans[e[1]] != -1:

                continue

            idx += 1

            ans[e[1]] = idx

            q.append((e[0], idx))

    print(*map(lambda x: x % color + 1, ans), sep="\n")

    return





if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-
import sys
import queue

input = sys.stdin.readline


def ii():
    return int(input().rstrip())


def mi():
    return map(int, input().rstrip().split())


def lmi():
    return list(map(int, input().rstrip().split()))


def fi():
    return float(input())


def mfi():
    return map(float, input().rstrip().split())


def lmfi():
    return list(map(float, input().rstrip().split()))


def li():
    return list(input().rstrip())


def exit(*arg):
    print(*arg)
    sys.exit()


# template
def main():
    n = ii()
    g = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = mi()
        g[a - 1].append((b - 1, i))
        g[b - 1].append((a - 1, i))
    color = max([len(g[i]) for i in range(n)])
    print(color)
    q = queue.Queue()
    ans = [-1 for i in range(n - 1)]
    idx = 0
    q.put((0, 0))
    while not q.empty():
        t, idx = q.get()
        for e in g[t]:
            if ans[e[1]] != -1:
                continue
            idx += 1
            ans[e[1]] = idx
            q.put((e[0], idx))
    print(*map(lambda x: x % color + 1, ans), sep="\n")
    return


if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
import sys
import collections

input = sys.stdin.readline


def ii():
    return int(input().rstrip())


def mi():
    return map(int, input().rstrip().split())


def lmi():
    return list(map(int, input().rstrip().split()))


def fi():
    return float(input().rstrip())


def mfi():
    return map(float, input().rstrip().split())


def lmfi():
    return list(map(float, input().rstrip().split()))


def li():
    return list(input().rstrip())


def exit(*arg):
    print(*arg)
    sys.exit()


# template
def main():
    n = ii()
    g = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = mi()
        g[a - 1].append((b - 1, i))
        g[b - 1].append((a - 1, i))
    color = max([len(g[i]) for i in range(n)])
    print(color)
    q = collections.deque()
    ans = [-1 for i in range(n - 1)]
    idx = 0
    q.append((0, 0))
    while len(q):
        t, idx = q.popleft()
        for e in g[t]:
            if ans[e[1]] != -1:
                continue
            idx += 1
            ans[e[1]] = idx
            q.append((e[0], idx))
    print(*map(lambda x: x % color + 1, ans), sep="\n")
    return


if __name__ == "__main__":
    main()

-import queue +import collections -    return float(input()) +    return float(input().rstrip()) -    q = queue.Queue() +    q = collections.deque() -    q.put((0, 0)) -    while not q.empty(): -        t, idx = q.get() +    q.append((0, 0)) +    while len(q): +        t, idx = q.popleft() -            q.put((e[0], idx)) +            q.append((e[0], idx))