import sys

sys.setrecursionlimit(100000)





def rootedTree(node,parent,root,num):

    A.append([node,parent,root,num])

    for root_num,num in root:

            rootedTree(root_num,node,tree[root_num],num)





n=int(eval(input()))

AB=[list(map(int,input().split()))+[i+1] for i in range(n-1)]

A=[]

tree=[[] for i in range(n+1)]

for a,b,c in AB:

    tree[a] +=[[b,c]]



rootedTree(1,0,tree[1],0)

ans=[0]*n

for node,parent,root,num in A:

    flag=0

    for i,j in enumerate(root):

        if ans[num]==i+1:flag=1

        ans[j[1]]=i+1+flag



print((max(ans)))

for i in range(1,n):print((ans[i]))
import sys

sys.setrecursionlimit(10**7)





def rootedTree(node,parent,root,num):

    A.append([node,parent,root,num])

    for root_num,num in root:

            rootedTree(root_num,node,tree[root_num],num)





n=int(eval(input()))

AB=[list(map(int,input().split()))+[i+1] for i in range(n-1)]

A=[]

tree=[[] for i in range(n+1)]

for a,b,c in AB:

    tree[a] +=[[b,c]]



rootedTree(1,0,tree[1],0)

ans=[0]*n

for node,parent,root,num in A:

    flag=0

    for i,j in enumerate(root):

        if ans[num]==i+1:flag=1

        ans[j[1]]=i+1+flag



print((max(ans)))

for i in range(1,n):print((ans[i]))
import sys

sys.setrecursionlimit(100000)


def rootedTree(node, parent, root, num):
    A.append([node, parent, root, num])
    for root_num, num in root:
        rootedTree(root_num, node, tree[root_num], num)


n = int(eval(input()))
AB = [list(map(int, input().split())) + [i + 1] for i in range(n - 1)]
A = []
tree = [[] for i in range(n + 1)]
for a, b, c in AB:
    tree[a] += [[b, c]]
rootedTree(1, 0, tree[1], 0)
ans = [0] * n
for node, parent, root, num in A:
    flag = 0
    for i, j in enumerate(root):
        if ans[num] == i + 1:
            flag = 1
        ans[j[1]] = i + 1 + flag
print((max(ans)))
for i in range(1, n):
    print((ans[i]))

import sys

sys.setrecursionlimit(10**7)


def rootedTree(node, parent, root, num):
    A.append([node, parent, root, num])
    for root_num, num in root:
        rootedTree(root_num, node, tree[root_num], num)


n = int(eval(input()))
AB = [list(map(int, input().split())) + [i + 1] for i in range(n - 1)]
A = []
tree = [[] for i in range(n + 1)]
for a, b, c in AB:
    tree[a] += [[b, c]]
rootedTree(1, 0, tree[1], 0)
ans = [0] * n
for node, parent, root, num in A:
    flag = 0
    for i, j in enumerate(root):
        if ans[num] == i + 1:
            flag = 1
        ans[j[1]] = i + 1 + flag
print((max(ans)))
for i in range(1, n):
    print((ans[i]))

-sys.setrecursionlimit(100000) +sys.setrecursionlimit(10**7)