from collections import deque





def solve(string):

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

    # i != j => (ai, bi) != (aj, bj)

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

    color = [set([]) 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 = list(next_[c].items())

        use = set(range(1, len(_next) + 1)) - color[c]

        _next = (k for k, v in _next if v == 0)

        for _n, u in zip(_next, use):

            queue.append(_n)

            next_[c][_n] = u

            next_[_n][c] = u

            color[c].add(u)

            color[_n].add(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()))

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

    # color = [set([]) 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 = list(next_[c].items())

        # use = set(range(1, len(_next) + 1)) - color[c]

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

        _next = (k for k, v in _next if v == 0)

        for _n, u in zip(_next, use):

            queue.append(_n)

            next_[c][_n] = u

            next_[_n][c] = u

            # color[c].add(u)

            # color[_n].add(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()))
    # i != j => (ai, bi) != (aj, bj)
    next_ = [dict([]) for _ in range(n + 1)]
    color = [set([]) 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 = list(next_[c].items())
        use = set(range(1, len(_next) + 1)) - color[c]
        _next = (k for k, v in _next if v == 0)
        for _n, u in zip(_next, use):
            queue.append(_n)
            next_[c][_n] = u
            next_[_n][c] = u
            color[c].add(u)
            color[_n].add(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()))
    next_ = [dict([]) for _ in range(n + 1)]
    # color = [set([]) 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 = list(next_[c].items())
        # use = set(range(1, len(_next) + 1)) - color[c]
        use = set(range(1, len(_next) + 1)) - set(next_[c].values())
        _next = (k for k, v in _next if v == 0)
        for _n, u in zip(_next, use):
            queue.append(_n)
            next_[c][_n] = u
            next_[_n][c] = u
            # color[c].add(u)
            # color[_n].add(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())))

-    # i != j => (ai, bi) != (aj, bj) -    color = [set([]) for _ in range(n + 1)] +    # color = [set([]) for _ in range(n + 1)] -        use = set(range(1, len(_next) + 1)) - color[c] +        # use = set(range(1, len(_next) + 1)) - color[c] +        use = set(range(1, len(_next) + 1)) - set(next_[c].values()) -            color[c].add(u) -            color[_n].add(u) +            # color[c].add(u) +            # color[_n].add(u)