#python3

from collections import deque



class Edge:

    def __init__(self, to, d):

        self.to = to

        self.d = d



def main():

    n = int(eval(input()))

    g = [[] for _ in range(n)]

    for i in range(n-1):

        a, b = [int(x)-1 for x in input().split()]

        g[a].append(Edge(b, i))

        g[b].append(Edge(a, i))



    dq = deque() 

    dq.append(0) 

    done = [0 for _ in range(n)]

    done[0] = 1

    ans = [0 for _ in range(n-1)]





    while len(dq):

        v = dq.pop()

        c = -1

        for i in range(len(g[v])):

            u = g[v][i].to

            ei = g[v][i].d

            if done[u]:

                c = ans[ei]

        k = 1

        for i in range(len(g[v])): 

            u = g[v][i].to

            ei = g[v][i].d

            if done[u]:

                continue 

            if k == c:

                k += 1

            ans[ei] = k

            k += 1

            dq.append(u)

            done[u] =  1

            



    mx = 0

    for i in range(len(g)):

        mx = max(mx, len(g[i]))



    print(mx)

    for i in ans:

        print(i)

main()
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import deque 



class Edge:

    def __init__(self, to, id):

        self.to = to

        self.id = id



def main():

    

    n = int(readline())

    g = [[] for _ in range(n)]



    for i in range(n-1):

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

        g[a-1].append(Edge(b-1, i))

        g[b-1].append(Edge(a-1, i))



    dq = deque()    

    done = [0 for _ in range(n)]

    dq.append(0)

    done[0] = 1

    edgecolor = [0 for _ in range(n-1)]



    while len(dq) > 0: 

        v = dq.pop()

        c = -1

        for i in range(len(g[v])):

            nx = g[v][i].to

            edge_id = g[v][i].id

            if done[nx]:

                c = edgecolor[edge_id]

        k = 1

        for i in range(len(g[v])):

            nx = g[v][i].to

            edge_id = g[v][i].id

            if done[nx]:

                continue

            if k == c:

                k += 1

            edgecolor[edge_id] = k

            k += 1  

            done[nx] = 1

            dq.append(nx)



    mx = max(edgecolor) 

    print(mx)

    for ec in edgecolor:

        print(ec)



if __name__ == '__main__':

    main()

# python3
from collections import deque


class Edge:
    def __init__(self, to, d):
        self.to = to
        self.d = d


def main():
    n = int(eval(input()))
    g = [[] for _ in range(n)]
    for i in range(n - 1):
        a, b = [int(x) - 1 for x in input().split()]
        g[a].append(Edge(b, i))
        g[b].append(Edge(a, i))
    dq = deque()
    dq.append(0)
    done = [0 for _ in range(n)]
    done[0] = 1
    ans = [0 for _ in range(n - 1)]
    while len(dq):
        v = dq.pop()
        c = -1
        for i in range(len(g[v])):
            u = g[v][i].to
            ei = g[v][i].d
            if done[u]:
                c = ans[ei]
        k = 1
        for i in range(len(g[v])):
            u = g[v][i].to
            ei = g[v][i].d
            if done[u]:
                continue
            if k == c:
                k += 1
            ans[ei] = k
            k += 1
            dq.append(u)
            done[u] = 1
    mx = 0
    for i in range(len(g)):
        mx = max(mx, len(g[i]))
    print(mx)
    for i in ans:
        print(i)


main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


class Edge:
    def __init__(self, to, id):
        self.to = to
        self.id = id


def main():
    n = int(readline())
    g = [[] for _ in range(n)]
    for i in range(n - 1):
        a, b = list(map(int, readline().split()))
        g[a - 1].append(Edge(b - 1, i))
        g[b - 1].append(Edge(a - 1, i))
    dq = deque()
    done = [0 for _ in range(n)]
    dq.append(0)
    done[0] = 1
    edgecolor = [0 for _ in range(n - 1)]
    while len(dq) > 0:
        v = dq.pop()
        c = -1
        for i in range(len(g[v])):
            nx = g[v][i].to
            edge_id = g[v][i].id
            if done[nx]:
                c = edgecolor[edge_id]
        k = 1
        for i in range(len(g[v])):
            nx = g[v][i].to
            edge_id = g[v][i].id
            if done[nx]:
                continue
            if k == c:
                k += 1
            edgecolor[edge_id] = k
            k += 1
            done[nx] = 1
            dq.append(nx)
    mx = max(edgecolor)
    print(mx)
    for ec in edgecolor:
        print(ec)


if __name__ == "__main__":
    main()

-# python3 +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines -    def __init__(self, to, d): +    def __init__(self, to, id): -        self.d = d +        self.id = id -    n = int(eval(input())) +    n = int(readline()) -        a, b = [int(x) - 1 for x in input().split()] -        g[a].append(Edge(b, i)) -        g[b].append(Edge(a, i)) +        a, b = list(map(int, readline().split())) +        g[a - 1].append(Edge(b - 1, i)) +        g[b - 1].append(Edge(a - 1, i)) +    done = [0 for _ in range(n)] -    done = [0 for _ in range(n)] -    ans = [0 for _ in range(n - 1)] -    while len(dq): +    edgecolor = [0 for _ in range(n - 1)] +    while len(dq) > 0: -            u = g[v][i].to -            ei = g[v][i].d -            if done[u]: -                c = ans[ei] +            nx = g[v][i].to +            edge_id = g[v][i].id +            if done[nx]: +                c = edgecolor[edge_id] -            u = g[v][i].to -            ei = g[v][i].d -            if done[u]: +            nx = g[v][i].to +            edge_id = g[v][i].id +            if done[nx]: -            ans[ei] = k +            edgecolor[edge_id] = k -            dq.append(u) -            done[u] = 1 -    mx = 0 -    for i in range(len(g)): -        mx = max(mx, len(g[i])) +            done[nx] = 1 +            dq.append(nx) +    mx = max(edgecolor) -    for i in ans: -        print(i) +    for ec in edgecolor: +        print(ec) -main() +if __name__ == "__main__": +    main()