def main():

    import sys

    readline = sys.stdin.buffer.readline

    read = sys.stdin.buffer.read

    N = int(readline())

    R = [[int(i) for i in r.split()] for r in read().rstrip().split(b'\n')]

    G = [[] for _ in range(N)]

    edge = {}

    ans_key = []

    for a, b in R:

        G[a-1].append(b-1)

        G[b-1].append(a-1)

        edge[(a-1, b-1)] = -1

        ans_key.append((a-1, b-1))

    max_g = max(len(g) for g in G)



    def dfs(max_g):

        todo = [0]

        seen = [False]*N

        seen[0] = True

        par = [-1]*N

        while todo:

            u = todo.pop()

            k = 0

            c = edge[(par[u], u)] if u != 0 else 0

            for v in G[u]:

                if seen[v]:

                    continue

                seen[v] = True

                todo.append(v)

                par[v] = u

                k += 1

                if k == c:

                    k += 1

                    if max_g < k:

                        k = 1

                if u < v:

                    edge[(u, v)] = k

                else:

                    edge[(v, u)] = k



    dfs(max_g)

    print(max_g)

    for k in ans_key:

        print((edge[k]))





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    G = [[] for _ in range(N)]

    edge = {}

    edge_order = [0]*(N-1)

    for i in range(N-1):

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

        G[a].append(b)

        G[b].append(a)

        edge[a*N + b] = -1  # 辺(a,b)の色

        edge_order[i] = a*N + b

    # 辺彩色

    # 最大次数だけ色があればよさそう？

    # BFSで塗っていく

    # ある辺を塗るときに必要なのは，親の辺の色と，同じ親の頂点を持つ

    # 辺のうち彩色済みの色（陽に持たなくてよい）

    max_deg = max(len(G[i]) for i in range(N))



    from collections import deque



    def bfs(s):

        que = deque([])

        par = [-1]*N

        par_color = [-1]*N

        c = 0

        que.append(s)

        while que:

            pos = que.popleft()

            for v in G[pos]:

                if par[pos] == v:

                    continue

                if par_color[pos] == c:

                    c += 1

                    if c == max_deg:

                        c = 0

                if pos < v:

                    edge[pos * N + v] = c

                else:

                    edge[v * N + pos] = c

                par[v] = pos

                par_color[v] = c

                que.append(v)

                c += 1

                if c == max_deg:

                    c = 0



    bfs(0)



    print(max_deg)

    for i in range(N-1):

        print((edge[edge_order[i]] + 1))





if __name__ == '__main__':

    main()

def main():
    import sys

    readline = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read
    N = int(readline())
    R = [[int(i) for i in r.split()] for r in read().rstrip().split(b"\n")]
    G = [[] for _ in range(N)]
    edge = {}
    ans_key = []
    for a, b in R:
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)
        edge[(a - 1, b - 1)] = -1
        ans_key.append((a - 1, b - 1))
    max_g = max(len(g) for g in G)

    def dfs(max_g):
        todo = [0]
        seen = [False] * N
        seen[0] = True
        par = [-1] * N
        while todo:
            u = todo.pop()
            k = 0
            c = edge[(par[u], u)] if u != 0 else 0
            for v in G[u]:
                if seen[v]:
                    continue
                seen[v] = True
                todo.append(v)
                par[v] = u
                k += 1
                if k == c:
                    k += 1
                    if max_g < k:
                        k = 1
                if u < v:
                    edge[(u, v)] = k
                else:
                    edge[(v, u)] = k

    dfs(max_g)
    print(max_g)
    for k in ans_key:
        print((edge[k]))


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    edge = {}
    edge_order = [0] * (N - 1)
    for i in range(N - 1):
        a, b = (int(i) - 1 for i in input().split())
        G[a].append(b)
        G[b].append(a)
        edge[a * N + b] = -1  # 辺(a,b)の色
        edge_order[i] = a * N + b
    # 辺彩色
    # 最大次数だけ色があればよさそう？
    # BFSで塗っていく
    # ある辺を塗るときに必要なのは，親の辺の色と，同じ親の頂点を持つ
    # 辺のうち彩色済みの色（陽に持たなくてよい）
    max_deg = max(len(G[i]) for i in range(N))
    from collections import deque

    def bfs(s):
        que = deque([])
        par = [-1] * N
        par_color = [-1] * N
        c = 0
        que.append(s)
        while que:
            pos = que.popleft()
            for v in G[pos]:
                if par[pos] == v:
                    continue
                if par_color[pos] == c:
                    c += 1
                    if c == max_deg:
                        c = 0
                if pos < v:
                    edge[pos * N + v] = c
                else:
                    edge[v * N + pos] = c
                par[v] = pos
                par_color[v] = c
                que.append(v)
                c += 1
                if c == max_deg:
                    c = 0

    bfs(0)
    print(max_deg)
    for i in range(N - 1):
        print((edge[edge_order[i]] + 1))


if __name__ == "__main__":
    main()

-    import sys - -    readline = sys.stdin.buffer.readline -    read = sys.stdin.buffer.read -    N = int(readline()) -    R = [[int(i) for i in r.split()] for r in read().rstrip().split(b"\n")] +    N = int(eval(input())) -    ans_key = [] -    for a, b in R: -        G[a - 1].append(b - 1) -        G[b - 1].append(a - 1) -        edge[(a - 1, b - 1)] = -1 -        ans_key.append((a - 1, b - 1)) -    max_g = max(len(g) for g in G) +    edge_order = [0] * (N - 1) +    for i in range(N - 1): +        a, b = (int(i) - 1 for i in input().split()) +        G[a].append(b) +        G[b].append(a) +        edge[a * N + b] = -1  # 辺(a,b)の色 +        edge_order[i] = a * N + b +    # 辺彩色 +    # 最大次数だけ色があればよさそう？ +    # BFSで塗っていく +    # ある辺を塗るときに必要なのは，親の辺の色と，同じ親の頂点を持つ +    # 辺のうち彩色済みの色（陽に持たなくてよい） +    max_deg = max(len(G[i]) for i in range(N)) +    from collections import deque -    def dfs(max_g): -        todo = [0] -        seen = [False] * N -        seen[0] = True +    def bfs(s): +        que = deque([]) -        while todo: -            u = todo.pop() -            k = 0 -            c = edge[(par[u], u)] if u != 0 else 0 -            for v in G[u]: -                if seen[v]: +        par_color = [-1] * N +        c = 0 +        que.append(s) +        while que: +            pos = que.popleft() +            for v in G[pos]: +                if par[pos] == v: -                seen[v] = True -                todo.append(v) -                par[v] = u -                k += 1 -                if k == c: -                    k += 1 -                    if max_g < k: -                        k = 1 -                if u < v: -                    edge[(u, v)] = k +                if par_color[pos] == c: +                    c += 1 +                    if c == max_deg: +                        c = 0 +                if pos < v: +                    edge[pos * N + v] = c -                    edge[(v, u)] = k +                    edge[v * N + pos] = c +                par[v] = pos +                par_color[v] = c +                que.append(v) +                c += 1 +                if c == max_deg: +                    c = 0 -    dfs(max_g) -    print(max_g) -    for k in ans_key: -        print((edge[k])) +    bfs(0) +    print(max_deg) +    for i in range(N - 1): +        print((edge[edge_order[i]] + 1))