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

N = int(input())

edges = {}
counter = Counter()
nodes = defaultdict(set)

K = 0
for i in range(N - 1):
    u, v = map(int, input().split(' '))
    counter[u] += 1
    counter[v] += 1
    K = max(K, counter[u], counter[v])
    nodes[u].add(v)
    nodes[v].add(u)
    edges[(u, v)] = i

colors = set([1 + k for k in range(K)])
checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    if len(checked) == N:
        break
    for v, vc in zip(nodes[u] - checked, colors - {uc}):
        edge_colors[edges[(min(u, v), max(u, v))]] = vc
        queue.append((v, vc))

print(K)
for i in range(N - 1):
    print(edge_colors[i])


Fixed submission:
from collections import defaultdict, deque, Counter

N = int(input())

counter = Counter()
nodes = defaultdict(list)
edges = []

for i in range(N - 1):
    u, v = map(int, input().split(' '))
    nodes[u].append((v, i))
    nodes[v].append((u, i))
    edges.append((u, v))

K = 0
for node in nodes.values():
    K = max(K, len(node))

checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    color = 1
    for v, e in nodes[u]:
        if v in checked:
            continue
        if color == uc:
            color += 1
        edge_colors[e] = color
        queue.append((v, color))
        color += 1

print(K)
for i in range(N - 1):
    print(edge_colors[i])

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

N = int(input())

edges = []
counter = Counter()
nodes = defaultdict(set)

for _ in range(N - 1):
    u, v = map(int, input().split(' '))
    counter[u] += 1
    counter[v] += 1
    nodes[u].add(v)
    nodes[v].add(u)
    edges.append((u, v))

K = max(counter.values())
colors = set([1 + k for k in range(K)])

checked = set()
queue = deque([(1, 0)])
edge_colors = {}

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    if len(checked) == N:
        break
    for v, vc in zip(nodes[u] - checked, colors - {uc}):
        edge_colors[(min(u, v), max(u, v))] = vc
        queue.append((v, vc))

print(K)
for u, v in edges:
    print(edge_colors[(u, v)])


Fixed submission:
from collections import defaultdict, deque, Counter

N = int(input())

counter = Counter()
nodes = defaultdict(list)
edges = []

for i in range(N - 1):
    u, v = map(int, input().split(' '))
    nodes[u].append((v, i))
    nodes[v].append((u, i))
    edges.append((u, v))

K = 0
for node in nodes.values():
    K = max(K, len(node))

checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    color = 1
    for v, e in nodes[u]:
        if v in checked:
            continue
        if color == uc:
            color += 1
        edge_colors[e] = color
        queue.append((v, color))
        color += 1

print(K)
for i in range(N - 1):
    print(edge_colors[i])

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

N = int(input())

edges = []
counter = Counter()
nodes = defaultdict(set)

for _ in range(N - 1):
    u, v = map(int, input().split(' '))
    counter[u] += 1
    counter[v] += 1
    nodes[u].add(v)
    nodes[v].add(u)
    edges.append((u, v))

K = max(counter.values())
colors = set([1 + k for k in range(K)])

checked = set()
queue = deque([(1, 0)])
edge_colors = {}

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    for v, vc in zip(nodes[u] - checked, colors - {uc}):
        edge_colors[(min(u, v), max(u, v))] = vc
        queue.append((v, vc))

print(K)
for u, v in edges:
    print(edge_colors[(u, v)])


Fixed submission:
from collections import defaultdict, deque, Counter

N = int(input())

counter = Counter()
nodes = defaultdict(list)
edges = []

for i in range(N - 1):
    u, v = map(int, input().split(' '))
    nodes[u].append((v, i))
    nodes[v].append((u, i))
    edges.append((u, v))

K = 0
for node in nodes.values():
    K = max(K, len(node))

checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    color = 1
    for v, e in nodes[u]:
        if v in checked:
            continue
        if color == uc:
            color += 1
        edge_colors[e] = color
        queue.append((v, color))
        color += 1

print(K)
for i in range(N - 1):
    print(edge_colors[i])

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

N = int(input())

edges = []
counter = Counter()
nodes = defaultdict(set)

for _ in range(N - 1):
    u, v = map(int, input().split(' '))
    counter[u] += 1
    counter[v] += 1
    nodes[u].add(v)
    nodes[v].add(u)
    edges.append((u, v))

K = max(counter.values())
colors = set([1 + k for k in range(K)])

node_colors = defaultdict(set)
checked = set()
queue = deque([1])
edge_colors = {}

while queue:
    u = queue.popleft()
    checked.add(u)
    for v, c in zip(nodes[u] - checked, colors - node_colors[u]):
        node_colors[u].add(c)
        node_colors[v].add(c)
        edge_colors[(min(u, v), max(u, v))] = c
        queue.append(v)

print(K)
for u, v in edges:
    print(edge_colors[(u, v)])


Fixed submission:
from collections import defaultdict, deque, Counter

N = int(input())

counter = Counter()
nodes = defaultdict(list)
edges = []

for i in range(N - 1):
    u, v = map(int, input().split(' '))
    nodes[u].append((v, i))
    nodes[v].append((u, i))
    edges.append((u, v))

K = 0
for node in nodes.values():
    K = max(K, len(node))

checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    color = 1
    for v, e in nodes[u]:
        if v in checked:
            continue
        if color == uc:
            color += 1
        edge_colors[e] = color
        queue.append((v, color))
        color += 1

print(K)
for i in range(N - 1):
    print(edge_colors[i])

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

N = int(input())

edges = []
counter = Counter()
nodes = defaultdict(set)

for _ in range(N - 1):
    u, v = map(int, input().split(' '))
    counter[u] += 1
    counter[v] += 1
    nodes[u].add(v)
    nodes[v].add(u)
    edges.append((u, v))

K = max(counter.values())
colors = set([1 + k for k in range(K)])

node_colors = defaultdict(set)
checked = set()
queue = deque([1])
edge_colors = {}

while queue:
    u = queue.popleft()
    checked.add(u)
    for v in nodes[u]:
        if v in checked:
            continue
        c = (colors - node_colors[u] - node_colors[v]).pop()
        node_colors[u].add(c)
        node_colors[v].add(c)
        edge_colors[(min(u, v), max(u, v))] = c
        queue.append(v)

print(K)
for u, v in edges:
    print(edge_colors[(u, v)])


Fixed submission:
from collections import defaultdict, deque, Counter

N = int(input())

counter = Counter()
nodes = defaultdict(list)
edges = []

for i in range(N - 1):
    u, v = map(int, input().split(' '))
    nodes[u].append((v, i))
    nodes[v].append((u, i))
    edges.append((u, v))

K = 0
for node in nodes.values():
    K = max(K, len(node))

checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    color = 1
    for v, e in nodes[u]:
        if v in checked:
            continue
        if color == uc:
            color += 1
        edge_colors[e] = color
        queue.append((v, color))
        color += 1

print(K)
for i in range(N - 1):
    print(edge_colors[i])

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

N = int(input())

edges = []
counter = Counter()
nodes = defaultdict(set)

for _ in range(N - 1):
    u, v = map(int, input().split(' '))
    counter[u] += 1
    counter[v] += 1
    nodes[u].add(v)
    nodes[v].add(u)
    edges.append((u, v))

K = max(counter.values())
colors = set([1 + k for k in range(K)])

node_colors = defaultdict(set)
checked = set()
queue = deque([1])
edge_colors = {}

while queue:
    u = queue.popleft()
    checked.add(u)
    for v in nodes[u]:
        if v in checked:
            continue
        c = (colors - node_colors[u] - node_colors[v]).pop()
        node_colors[u].add(c)
        node_colors[v].add(c)
        edge_colors[(min(u, v), max(u, v))] = c
        queue.append(v)

print(K)
for u, v in edges:
    print(edge_colors[(u, v)])


Fixed submission:
from collections import defaultdict, deque, Counter

N = int(input())

counter = Counter()
nodes = defaultdict(list)
edges = []

for i in range(N - 1):
    u, v = map(int, input().split(' '))
    nodes[u].append((v, i))
    nodes[v].append((u, i))
    edges.append((u, v))

K = 0
for node in nodes.values():
    K = max(K, len(node))

checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    color = 1
    for v, e in nodes[u]:
        if v in checked:
            continue
        if color == uc:
            color += 1
        edge_colors[e] = color
        queue.append((v, color))
        color += 1

print(K)
for i in range(N - 1):
    print(edge_colors[i])