import sys

from collections import defaultdict



sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

p2D = lambda x: print(*x, sep="\n")

def MI(): return map(int, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]



def main():

    def dfs(u,pu=-1,pc=-1):

        c=0

        for cu in to[u]:

            if cu==pu:continue

            c+=1

            if c==pc:c+=1

            ei=etoi[(u,cu)]

            e_color[ei]=c

            dfs(cu,u,c)



    to=defaultdict(list)

    n=int(input())

    etoi={}

    for i in range(n-1):

        a,b=map(int1,input().split())

        to[a].append(b)

        to[b].append(a)

        etoi[(a,b)]=etoi[(b,a)]=i

    #print(etoi)

    e_color=[-1]*(n-1)

    max_deg_u=max(to.items(),key=lambda x:len(x[1]))[0]

    dfs(max_deg_u)

    print(max(e_color))

    print(*e_color,sep="\n")



main()

from collections import *

import sys



sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

p2D = lambda x: print(*x, sep="\n")

def MI(): return map(int, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]



def main():

    def dfs(u=0,pu=-1,pc=-1):

        c=1

        for i,cu in to[u]:

            if cu==pu:continue

            if c==pc:c+=1

            ans[i]=c

            dfs(cu,u,c)

            c+=1



    to=defaultdict(list)

    n=int(input())

    for i in range(n-1):

        a,b=map(int1,input().split())

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

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

    ans=[-1]*(n-1)

    dfs()

    print(max(ans))

    print(*ans,sep="\n")



main()

import sys
from collections import defaultdict

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def main():
    def dfs(u, pu=-1, pc=-1):
        c = 0
        for cu in to[u]:
            if cu == pu:
                continue
            c += 1
            if c == pc:
                c += 1
            ei = etoi[(u, cu)]
            e_color[ei] = c
            dfs(cu, u, c)

    to = defaultdict(list)
    n = int(input())
    etoi = {}
    for i in range(n - 1):
        a, b = map(int1, input().split())
        to[a].append(b)
        to[b].append(a)
        etoi[(a, b)] = etoi[(b, a)] = i
    # print(etoi)
    e_color = [-1] * (n - 1)
    max_deg_u = max(to.items(), key=lambda x: len(x[1]))[0]
    dfs(max_deg_u)
    print(max(e_color))
    print(*e_color, sep="\n")


main()

from collections import *
import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def main():
    def dfs(u=0, pu=-1, pc=-1):
        c = 1
        for i, cu in to[u]:
            if cu == pu:
                continue
            if c == pc:
                c += 1
            ans[i] = c
            dfs(cu, u, c)
            c += 1

    to = defaultdict(list)
    n = int(input())
    for i in range(n - 1):
        a, b = map(int1, input().split())
        to[a].append([i, b])
        to[b].append([i, a])
    ans = [-1] * (n - 1)
    dfs()
    print(max(ans))
    print(*ans, sep="\n")


main()

+from collections import * -from collections import defaultdict -    def dfs(u, pu=-1, pc=-1): -        c = 0 -        for cu in to[u]: +    def dfs(u=0, pu=-1, pc=-1): +        c = 1 +        for i, cu in to[u]: -            c += 1 -            ei = etoi[(u, cu)] -            e_color[ei] = c +            ans[i] = c +            c += 1 -    etoi = {} -        to[a].append(b) -        to[b].append(a) -        etoi[(a, b)] = etoi[(b, a)] = i -    # print(etoi) -    e_color = [-1] * (n - 1) -    max_deg_u = max(to.items(), key=lambda x: len(x[1]))[0] -    dfs(max_deg_u) -    print(max(e_color)) -    print(*e_color, sep="\n") +        to[a].append([i, b]) +        to[b].append([i, a]) +    ans = [-1] * (n - 1) +    dfs() +    print(max(ans)) +    print(*ans, sep="\n")