import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**5)



def main():

    N = int(eval(input()))

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

    ans = []

    for i in range(N-1):

        a, b = list(map(int, input().split()))

        a -= 1

        b -= 1

        edges[a].append((b,i))

        edges[b].append((a,i))



    K = 0

    for i in range(N):

        K = max(K, len(edges[i]))



    visited = [False] * N



    def dfs(v, color):

        visited[v] = True

        for l, m in enumerate(edges[v]):

            if visited[m[0]]:

                continue

            color += 1

            color %= K

            ans.append((m[1],color))

            dfs(m[0], color)



    dfs(0,0)



    ans.sort()

    print(K)

    for a, b in ans:

        print((b+1))



if __name__ == "__main__":

    main()
import sys

sys.setrecursionlimit(1000000)

def main():

    N = int(eval(input()))

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

    for i in range(N-1):

        a, b = list(map(int, input().split()))

        a -= 1

        b -= 1

        edge[a].append([b,i])

        edge[b].append([a,i])

    color = [0] * (N-1)

    def dfs(s,p,c):

        tmp_c = 1

        for v, num in edge[s]:

            if v == p:

                continue

            if tmp_c == c:

                tmp_c += 1

            color[num] = tmp_c

            dfs(v,s,tmp_c)

            tmp_c += 1

    dfs(0,-1,0)

    print((max(color)))

    for c in color:

        print(c)





if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**5)


def main():
    N = int(eval(input()))
    edges = [[] for _ in range(N)]
    ans = []
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        edges[a].append((b, i))
        edges[b].append((a, i))
    K = 0
    for i in range(N):
        K = max(K, len(edges[i]))
    visited = [False] * N

    def dfs(v, color):
        visited[v] = True
        for l, m in enumerate(edges[v]):
            if visited[m[0]]:
                continue
            color += 1
            color %= K
            ans.append((m[1], color))
            dfs(m[0], color)

    dfs(0, 0)
    ans.sort()
    print(K)
    for a, b in ans:
        print((b + 1))


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(1000000)


def main():
    N = int(eval(input()))
    edge = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        edge[a].append([b, i])
        edge[b].append([a, i])
    color = [0] * (N - 1)

    def dfs(s, p, c):
        tmp_c = 1
        for v, num in edge[s]:
            if v == p:
                continue
            if tmp_c == c:
                tmp_c += 1
            color[num] = tmp_c
            dfs(v, s, tmp_c)
            tmp_c += 1

    dfs(0, -1, 0)
    print((max(color)))
    for c in color:
        print(c)


if __name__ == "__main__":
    main()

-input = sys.stdin.readline -sys.setrecursionlimit(10**5) +sys.setrecursionlimit(1000000) -    edges = [[] for _ in range(N)] -    ans = [] +    edge = [[] for _ in range(N)] -        edges[a].append((b, i)) -        edges[b].append((a, i)) -    K = 0 -    for i in range(N): -        K = max(K, len(edges[i])) -    visited = [False] * N +        edge[a].append([b, i]) +        edge[b].append([a, i]) +    color = [0] * (N - 1) -    def dfs(v, color): -        visited[v] = True -        for l, m in enumerate(edges[v]): -            if visited[m[0]]: +    def dfs(s, p, c): +        tmp_c = 1 +        for v, num in edge[s]: +            if v == p: -            color += 1 -            color %= K -            ans.append((m[1], color)) -            dfs(m[0], color) +            if tmp_c == c: +                tmp_c += 1 +            color[num] = tmp_c +            dfs(v, s, tmp_c) +            tmp_c += 1 -    dfs(0, 0) -    ans.sort() -    print(K) -    for a, b in ans: -        print((b + 1)) +    dfs(0, -1, 0) +    print((max(color))) +    for c in color: +        print(c)