from collections import OrderedDict, deque



n = int(eval(input()))

edges = [tuple(map(int, input().split())) for _ in range(n - 1)]

tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる.

coloring = OrderedDict()

for e in edges:

    a, b = e[0] - 1, e[1] - 1

    tree[a].append(b)

    tree[b].append(a)

    coloring[(a, b)] = 0



q = deque()

q_append = q.append

q_popleft = q.popleft

seen = [False] * n

q_append(0)

col_count_by_v = [set() for _ in range(n)]

while len(q):

    new_v = q_popleft()

    seen[new_v] = True

    color_i = 1  # One-based index.

    for adj in tree[new_v]:

        if seen[adj]:

            continue

        q_append(adj)

        while color_i in col_count_by_v[new_v]:

            color_i += 1

        coloring[(new_v, adj)] = color_i

        col_count_by_v[new_v].add(color_i)

        col_count_by_v[adj].add(color_i)

        color_i += 1



print((len(set(coloring.values()))))

for c in list(coloring.values()):

    print(c)

from collections import OrderedDict, deque





def main():

    n = int(eval(input()))

    edges = [tuple(map(int, input().split())) for _ in range(n - 1)]

    tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる.

    coloring = OrderedDict()

    for e in edges:

        a, b = e[0] - 1, e[1] - 1

        tree[a].append(b)

        tree[b].append(a)

        coloring[(a, b)] = 0



    q = deque()

    q_append = q.append

    q_popleft = q.popleft

    seen = [False] * n

    q_append(0)

    col_count_by_v = [set() for _ in range(n)]

    while len(q):

        new_v = q_popleft()

        seen[new_v] = True

        color_i = 1  # One-based index.

        for adj in tree[new_v]:

            if seen[adj]:

                continue

            q_append(adj)

            while color_i in col_count_by_v[new_v]:

                color_i += 1

            coloring[(new_v, adj)] = color_i

            col_count_by_v[new_v].add(color_i)

            col_count_by_v[adj].add(color_i)



    print((len(set(coloring.values()))))

    for c in list(coloring.values()):

        print(c)





if __name__ == '__main__':

    main()



# なんでか分からないが, こうして main() に仕舞ってあげたほうが少し早い.

from collections import OrderedDict, deque

n = int(eval(input()))
edges = [tuple(map(int, input().split())) for _ in range(n - 1)]
tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる.
coloring = OrderedDict()
for e in edges:
    a, b = e[0] - 1, e[1] - 1
    tree[a].append(b)
    tree[b].append(a)
    coloring[(a, b)] = 0
q = deque()
q_append = q.append
q_popleft = q.popleft
seen = [False] * n
q_append(0)
col_count_by_v = [set() for _ in range(n)]
while len(q):
    new_v = q_popleft()
    seen[new_v] = True
    color_i = 1  # One-based index.
    for adj in tree[new_v]:
        if seen[adj]:
            continue
        q_append(adj)
        while color_i in col_count_by_v[new_v]:
            color_i += 1
        coloring[(new_v, adj)] = color_i
        col_count_by_v[new_v].add(color_i)
        col_count_by_v[adj].add(color_i)
        color_i += 1
print((len(set(coloring.values()))))
for c in list(coloring.values()):
    print(c)

from collections import OrderedDict, deque


def main():
    n = int(eval(input()))
    edges = [tuple(map(int, input().split())) for _ in range(n - 1)]
    tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる.
    coloring = OrderedDict()
    for e in edges:
        a, b = e[0] - 1, e[1] - 1
        tree[a].append(b)
        tree[b].append(a)
        coloring[(a, b)] = 0
    q = deque()
    q_append = q.append
    q_popleft = q.popleft
    seen = [False] * n
    q_append(0)
    col_count_by_v = [set() for _ in range(n)]
    while len(q):
        new_v = q_popleft()
        seen[new_v] = True
        color_i = 1  # One-based index.
        for adj in tree[new_v]:
            if seen[adj]:
                continue
            q_append(adj)
            while color_i in col_count_by_v[new_v]:
                color_i += 1
            coloring[(new_v, adj)] = color_i
            col_count_by_v[new_v].add(color_i)
            col_count_by_v[adj].add(color_i)
    print((len(set(coloring.values()))))
    for c in list(coloring.values()):
        print(c)


if __name__ == "__main__":
    main()
# なんでか分からないが, こうして main() に仕舞ってあげたほうが少し早い.

-n = int(eval(input())) -edges = [tuple(map(int, input().split())) for _ in range(n - 1)] -tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる. -coloring = OrderedDict() -for e in edges: -    a, b = e[0] - 1, e[1] - 1 -    tree[a].append(b) -    tree[b].append(a) -    coloring[(a, b)] = 0 -q = deque() -q_append = q.append -q_popleft = q.popleft -seen = [False] * n -q_append(0) -col_count_by_v = [set() for _ in range(n)] -while len(q): -    new_v = q_popleft() -    seen[new_v] = True -    color_i = 1  # One-based index. -    for adj in tree[new_v]: -        if seen[adj]: -            continue -        q_append(adj) -        while color_i in col_count_by_v[new_v]: -            color_i += 1 -        coloring[(new_v, adj)] = color_i -        col_count_by_v[new_v].add(color_i) -        col_count_by_v[adj].add(color_i) -        color_i += 1 -print((len(set(coloring.values())))) -for c in list(coloring.values()): -    print(c) + +def main(): +    n = int(eval(input())) +    edges = [tuple(map(int, input().split())) for _ in range(n - 1)] +    tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる. +    coloring = OrderedDict() +    for e in edges: +        a, b = e[0] - 1, e[1] - 1 +        tree[a].append(b) +        tree[b].append(a) +        coloring[(a, b)] = 0 +    q = deque() +    q_append = q.append +    q_popleft = q.popleft +    seen = [False] * n +    q_append(0) +    col_count_by_v = [set() for _ in range(n)] +    while len(q): +        new_v = q_popleft() +        seen[new_v] = True +        color_i = 1  # One-based index. +        for adj in tree[new_v]: +            if seen[adj]: +                continue +            q_append(adj) +            while color_i in col_count_by_v[new_v]: +                color_i += 1 +            coloring[(new_v, adj)] = color_i +            col_count_by_v[new_v].add(color_i) +            col_count_by_v[adj].add(color_i) +    print((len(set(coloring.values())))) +    for c in list(coloring.values()): +        print(c) + + +if __name__ == "__main__": +    main() +# なんでか分からないが, こうして main() に仕舞ってあげたほうが少し早い.