Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    colors = set()
    colors.add(pc)

    for to, idx in edge[node]:
        if ec[idx] == 0:
            for c in range(1, N):
                if c not in colors:
                    ec[idx] = c
                    colors.add(c)
                    break

            dfs(to, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
ec = [0] * (N - 1)


def dfs(v, pc):
    colors = set()
    colors.add(pc)

    for idx, e in [x for x in enumerate(edge) if ec[x[0]] == 0 and v in x[1]]:
        for c in range(1, N):
            if c not in colors:
                ec[idx] = c
                colors.add(c)
                break

        nv = e[0] if e[1] == v else e[1]
        dfs(nv, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
ec = [0] * (N - 1)


def dfs(v, pc):
    colors = set()
    colors.add(pc)

    for idx, e in enumerate(edge):
        if v not in e:
            continue
        if ec[idx] == 0:
            for c in range(1, N):
                if c not in colors:
                    ec[idx] = c
                    colors.add(c)
                    break

            nv = e[0] if e[1] == v else e[1]
            dfs(nv, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
ec = [0] * (N - 1)


def dfs(v, pc):
    colors = set()
    colors.add(pc)

    for idx, e in enumerate(edge):
        if v not in e:
            continue
        if ec[idx] == 0:
            for c in range(1, N):
                if c not in colors:
                    ec[idx] = c
                    colors.add(c)
                    break

            nv = e[0] if e[1] == v else e[1]
            dfs(nv, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
ec = [0] * (N - 1)


def dfs(v, pc):
    colors = [True] * N
    colors[pc] = False

    for idx, e in [x for x in enumerate(edge) if v in x[1]]:
        if ec[idx] == 0:
            for idx_c, c in enumerate(colors):
                if c:
                    ec[idx] = idx_c
                    colors[idx_c] = False
                    break

            nv = e[0] if e[1] == v else e[1]
            dfs(nv, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
ec = [0] * (N - 1)


def dfs(v, pc):
    colors = set()
    colors.add(pc)

    for idx, e in [x for x in enumerate(edge) if v in x[1]]:
        if ec[idx] == 0:
            for c in range(1, N):
                if c not in colors:
                    ec[idx] = c
                    colors.add(c)
                    break

            nv = e[0] if e[1] == v else e[1]
            dfs(nv, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
ec = [0] * (N - 1)


def dfs(v, pc):
    colors = set()
    colors.add(pc)

    for idx, e in [x for x in enumerate(edge) if v in x[1]]:
        if ec[idx] == 0:
            for c in range(1, N):
                if c not in colors:
                    ec[idx] = c
                    colors.add(c)
                    break

            nv = e[0] if e[1] == v else e[1]
            dfs(nv, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
ec = [0] * (N - 1)


def dfs(v, pc):
    colors = set()
    colors.add(pc)

    for idx, e in [x for x in enumerate(edge) if v in x[1]]:
        if ec[idx] == 0:
            for c in range(1, N):
                if c not in colors:
                    ec[idx] = c
                    colors.add(c)
                    break

            nv = e[0] if e[1] == v else e[1]
            dfs(nv, c)


dfs(0, 0)
print(max(ec))
for c in ec:
    print(c)


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


N = int(input())
branch = [[0] + list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
vertex = [False] * N


def bfs():
    max_color = 0
    q = deque()
    v = 0
    bc = 0
    q.append((v, bc))

    while len(q):
        v, bc = q.popleft()
        vertex[v] = True
        b_list = [c for c in branch if v in c[1:]]

        color = 1
        for c in b_list:
            if color == bc:
                color += 1
            if (c[0] == 0):
                c[0] = color
                color += 1
            nv = c[1] if c[2] == v else c[2]
            if vertex[nv] is False:
                q.append((nv, c[0]))
        max_color = max(max_color, color - 1)

    return max_color


print(bfs())
for b in branch:
    print(b[0])


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


N = int(input())
branch = [[0] + list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
vertex = [False] * N


def bfs():
    max_color = 0
    q = deque()
    v = 0
    bc = 0
    q.append((v, bc))

    while len(q):
        v, bc = q.popleft()
        vertex[v] = True
        b_list = [c for c in branch if v in c[1:]]

        color = 1
        for c in b_list:
            if color == bc:
                color += 1
            if (c[0] == 0):
                c[0] = color
                color += 1
            nv = c[1] if c[2] == v else c[2]
            if vertex[nv] is False:
                q.append((nv, c[0]))
        max_color = max(max_color, color - 1)

    return max_color


print(bfs())
for b in branch:
    print(b[0])


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


N = int(input())
branch = [[0] + list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
branch_color = [0] * (N - 1)
vertex = [False] * N


def bfs():
    max_color = 0
    q = deque()
    v = 0
    bc = 0
    q.append((v, bc))

    while len(q):
        v, bc = q.popleft()
        vertex[v] = True
        b_list = [c for c in branch if v in c[1:]]

        color = 1
        for c in b_list:
            if color == bc:
                color += 1
            if (c[0] == 0):
                c[0] = color
                color += 1

        max_color = max(max_color, color - 1)

        for c in b_list:
            nv = c[1] if c[2] == v else c[2]
            if vertex[nv] is False:
                q.append((nv, c[0]))

    return max_color


print(bfs())
for b in branch:
    print(b[0])


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5 + 10)

N = int(input())

branch = [[0] + list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
branch_color = [0] * (N - 1)
vertex = [False] * N


def bfs():
    q = deque()
    v = 0
    bc = 0
    q.append((v, bc))

    while len(q):
        v, bc = q.popleft()
        vertex[v] = True
        b_list = [c for c in branch if v in c[1:]]

        for i in [x for x in range(len(b_list)) if x != bc]:
            if (b_list[i][0] == 0):
                b_list[i][0] = i

        for b in b_list:
            nv = b[1] if b[2] == v else b[2]
            if vertex[nv] is False:
                q.append(nv)


bfs()
for b in branch:
    print(b[0])


Fixed submission:
import sys


sys.setrecursionlimit(10 ** 6)

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


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


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