from collections import deque





def solve(string):

    n, *ab = list(map(int, string.split()))

    next_ = [dict([]) for _ in range(n + 1)]

    queue = deque([1])

    for a, b in zip(*[iter(ab)] * 2):

        next_[a][b] = 0

        next_[b][a] = 0

    while len(queue) > 0:

        c = queue.popleft()

        _next = next_[c]

        use = set(range(1, len(list(_next.keys())) + 1)) - set(next_[c].values())

        for _n, u in zip((k for k, v in list(_next.items()) if v == 0), use):

            queue.append(_n)

            next_[c][_n] = u

            next_[_n][c] = u

    return str("{}\n{}".format(max([len(list(x.keys())) for x in next_]),

                               "\n".join(str(next_[a][b]) for a, b in zip(*[iter(ab)] * 2))))





if __name__ == '__main__':

    import sys

    print((solve(sys.stdin.read().strip())))

from collections import deque





def solve(string):

    n, *ab = list(map(int, string.split()))

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

    q = deque([1])

    c = [0] * (n + 1)

    for a, b in zip(*[iter(ab)] * 2):

        e[a].append(b)

    while q:

        s = q.popleft()

        d = 0

        for t in e[s]:

            d += 1 + (d + 1 == c[s])

            c[t] = d

            q.append(t)

    return str("{}\n{}".format(max(c), "\n".join(str(c[b]) for _, b in zip(*[iter(ab)] * 2))))





if __name__ == '__main__':

    import sys

    print((solve(sys.stdin.read().strip())))

from collections import deque


def solve(string):
    n, *ab = list(map(int, string.split()))
    next_ = [dict([]) for _ in range(n + 1)]
    queue = deque([1])
    for a, b in zip(*[iter(ab)] * 2):
        next_[a][b] = 0
        next_[b][a] = 0
    while len(queue) > 0:
        c = queue.popleft()
        _next = next_[c]
        use = set(range(1, len(list(_next.keys())) + 1)) - set(next_[c].values())
        for _n, u in zip((k for k, v in list(_next.items()) if v == 0), use):
            queue.append(_n)
            next_[c][_n] = u
            next_[_n][c] = u
    return str(
        "{}\n{}".format(
            max([len(list(x.keys())) for x in next_]),
            "\n".join(str(next_[a][b]) for a, b in zip(*[iter(ab)] * 2)),
        )
    )


if __name__ == "__main__":
    import sys

    print((solve(sys.stdin.read().strip())))

from collections import deque


def solve(string):
    n, *ab = list(map(int, string.split()))
    e = [[] for _ in range(n + 1)]
    q = deque([1])
    c = [0] * (n + 1)
    for a, b in zip(*[iter(ab)] * 2):
        e[a].append(b)
    while q:
        s = q.popleft()
        d = 0
        for t in e[s]:
            d += 1 + (d + 1 == c[s])
            c[t] = d
            q.append(t)
    return str(
        "{}\n{}".format(max(c), "\n".join(str(c[b]) for _, b in zip(*[iter(ab)] * 2)))
    )


if __name__ == "__main__":
    import sys

    print((solve(sys.stdin.read().strip())))

-    next_ = [dict([]) for _ in range(n + 1)] -    queue = deque([1]) +    e = [[] for _ in range(n + 1)] +    q = deque([1]) +    c = [0] * (n + 1) -        next_[a][b] = 0 -        next_[b][a] = 0 -    while len(queue) > 0: -        c = queue.popleft() -        _next = next_[c] -        use = set(range(1, len(list(_next.keys())) + 1)) - set(next_[c].values()) -        for _n, u in zip((k for k, v in list(_next.items()) if v == 0), use): -            queue.append(_n) -            next_[c][_n] = u -            next_[_n][c] = u +        e[a].append(b) +    while q: +        s = q.popleft() +        d = 0 +        for t in e[s]: +            d += 1 + (d + 1 == c[s]) +            c[t] = d +            q.append(t) -        "{}\n{}".format( -            max([len(list(x.keys())) for x in next_]), -            "\n".join(str(next_[a][b]) for a, b in zip(*[iter(ab)] * 2)), -        ) +        "{}\n{}".format(max(c), "\n".join(str(c[b]) for _, b in zip(*[iter(ab)] * 2)))