qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))

K = max(len(e) for e in E)
print(K)

Ans = [-1] * (N-1)
def dfs(v, pc=-1, p=-1):
    c = 1
    for u, idx in E[v]:
        if (u == p):
            continue
        if (c == pc): 
            c += 1
        Ans[idx] = c
        c += 1
        dfs(u, c, v)
        
dfs(1)
print("\n".join(map(str, Ans)))

# Fixed code:
import sys
sys.setrecursionlimit(500000)

N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))

K = max(len(e) for e in E)
print(K)

Ans = [-1] * (N-1)
def dfs(v, pc=-1, p=-1):
    c = 1
    for u, idx in E[v]:
        if (u == p):
            continue
        if (c == pc): 
            c += 1
        Ans[idx] = c
        dfs(u, c, v)
        c += 1

dfs(1)
print("\n".join(map(str, Ans)))
# Buggy code:
# ABC146d
ans = 1


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())

    n = int(input())

    edges = [list() for _ in range(n)]
    colors = [-1]*(n-1)

    for i in range(n - 1):
        a, b = map(int, input().split())
        edges[a - 1].append((b - 1, i))
        edges[b - 1].append((a - 1, i))

    def dfs(i, color, pre):
        for e in edges[i]:
            if e[0] == pre:
                continue
            global ans
            if ans < len(edges[i]):
                ans = len(edges[i])
            nc = 0
            for j in range(ans):
                if j == color:
                    continue
                nc = j
            colors[e[1]] = nc
            dfs(e[0], nc, i)
    dfs(0, 0, -1)
    print(ans)
    for i in colors:
        print(i+1)


if __name__ == '__main__':
    main()


# Fixed code:
# ABC146d
ans = 1


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())

    n = int(input())

    edges = [list() for _ in range(n)]
    colors = [-1] * (n - 1)

    for i in range(n - 1):
        a, b = map(int, input().split())
        edges[a - 1].append((b - 1, i))
        edges[b - 1].append((a - 1, i))

    def dfs(i, color, pre):
        nc = 0 if color != 0 else 1
        for e in edges[i]:
            if e[0] == pre:
                continue
            global ans
            if ans < len(edges[i]):
                ans = len(edges[i])
            colors[e[1]] = nc
            dfs(e[0], nc, i)
            nc += 1
            if nc == color:
                nc += 1
    dfs(0, -1, -1)
    print(ans)
    for i in colors:
        print(i+1)


if __name__ == '__main__':
    main()
# Buggy code:
n=int(input())
g=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append((b-1,i))

vc=[0] * n
ec=[-1]*(n-1)
for p,ci in enumerate(g):
    color = 1
    for c, i in ci:
        if vc[p] == c:
            color += 1
        vc[c] = color
        ec[i] = color
        color += 1
        

print(max(ec))
for i in range(n-1):
    print(ec[i])


# Fixed code:
n=int(input())
g=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append((b-1,i))

vc=[0] * n
ec=[-1]*(n-1)
for p,ci in enumerate(g):
    color = 1
    for c, i in ci:
        if vc[p] == color:
            color += 1
        vc[c] = color
        ec[i] = color
        color += 1
        

print(max(ec))
for i in range(n-1):
    print(ec[i])
# Buggy code:
import collections
from collections import deque
def tree(s):

    INF=-10**9
    dis = [INF for i in range(n)]
    ans = [INF for i in range(n)]
    dis[s]=0
    def bfs():
        d = deque()
        d.append(s)

        while len(d):
            x = d.popleft()
            cnt=1

            for i in range(len(b[x])):
                y=b[x][i]
                if dis[y] == INF:
                    d.append(y)
                    dis[y]=dis[x]+1
                    if ans[x]!=cnt:
                        ans[y]=cnt
                        cnt+=1
                    else:
                        cnt+=1
                        ans[y]=cnt
                        cnt+=1

        return ans
    return bfs()

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

for i in range(n-1):
    b[a[i][0]-1].append(a[i][1]-1)

x=tree(0)
print(max(x))
for i in range(1,n):
    print(x[a[i][1]-1])

# Fixed code:
import collections
from collections import deque
def tree(s):

    INF=-10**9
    dis = [INF for i in range(n)]
    ans = [INF for i in range(n)]
    dis[s]=0
    def bfs():
        d = deque()
        d.append(s)

        while len(d):
            x = d.popleft()
            cnt=1

            for i in range(len(b[x])):
                y=b[x][i]
                if dis[y] == INF:
                    d.append(y)
                    dis[y]=dis[x]+1
                    if ans[x]!=cnt:
                        ans[y]=cnt
                        cnt+=1
                    else:
                        cnt+=1
                        ans[y]=cnt
                        cnt+=1

        return ans
    return bfs()

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

for i in range(n-1):
    b[a[i][0]-1].append(a[i][1]-1)

x=tree(0)
print(max(x))
for i in range(n-1):
    print(x[a[i][1]-1])
# Buggy code:
from queue import deque

N = int(input())

A = []
B = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    A.append([a, b])
    B[a-1].append(b-1)

X = max(len(i) for i in B)

print(X)

q = deque([0])
color = [[-1]*N]
ans = {}
while q:
    nord = q.popleft()
    c = 0
    for i, v in enumerate(B[nord]):
        if color[v] == i:
            c += 1
        color[i] = c + i 
        ans[(nord, i)] = c + i
        q.append(v)

for i, j in B:
    print(ans[(i-1, j-1)]+1)

# Fixed code:
from queue import deque

N = int(input())

A = []
B = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    A.append([a, b])
    
for i, j in A:
    B[i-1].append(j-1)

q = deque([0])
color = [-1]*N
ans = {}
saidai = 0
while q:
    nord = q.popleft()
    c = 0
    for i, v in enumerate(B[nord]):
        if color[nord] == i:
            c += 1
        color[v] = c + i 
        ans[(nord, v)] = c + i
        q.append(v)
        saidai = max(saidai,i+c+1)

print(saidai)

for i, j in A:
    print(1+ans[(i-1, j-1)])
# Buggy code:
from collections import deque

N = int(input())

dic = {i:[] for i in range(1,N+1)}

rlt = [0]*(N-1)

for i in range(N-1):
  a,b = map(int, input().split())
  dic[a].append((b,i))
  dic[b].append((a,i))
  
h = deque([(1,1)])

while h:
  j = 1
  c = 0
  t = h.popleft()
  for k in dic[t[0]]:
    if k[0] == t[1]:
      c = rlt[k[1]]
      break
  for k in dic[t[0]]:
    if k[0] == t[1]:
      continue
    if c == j:
      j += 1
    rlt[k[1]] = j
    h.append((k[0],t[0]))
    j += 1
      
print(rlt)

# Fixed code:
from collections import deque

N = int(input())

dic = {i:[] for i in range(1,N+1)}

rlt = [0]*(N-1)

for i in range(N-1):
  a,b = map(int, input().split())
  dic[a].append((b,i))
  dic[b].append((a,i))
  
h = deque([(1,1)])

while h:
  j = 1
  c = 0
  t = h.popleft()
  for k in dic[t[0]]:
    if k[0] == t[1]:
      c = rlt[k[1]]
      break
  for k in dic[t[0]]:
    if k[0] == t[1]:
      continue
    if c == j:
      j += 1
    rlt[k[1]] = j
    h.append((k[0],t[0]))
    j += 1
    
print(max(rlt))  
for l in rlt:
  print(l)
# Buggy code:
import sys
input = sys.stdin.buffer.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
  
def make_tree(graph, root) -> (list, list, list):
    INF = 10 ** 15
    dist = [INF] * len(graph)
    parent = [-1] * len(graph)
    stack = [root]
    dist[root] = 0
    order = []
    parent[root] = root
    while stack:
        s = stack.pop()
        order.append(s)
        for g in graph[s]:
            if dist[g] > dist[s] + 1:
                dist[g] = dist[s] + 1
                parent[g] = s
                stack.append(g)
    return dist, parent, order
    
dist, parent, order = make_tree(graph, 1)

color = [-1] * (N + 1)
for s in order:
    ng = color[s]
    c = 1
    for g in graph[s]:
        if parent[s] == g:
            continue
        if c == ng:
            c += 1
        color[g] = c
        c += 1
print(color)

answer = []
for a, b in AB:
    if parent[a] == b:
        answer.append(color[a])
    else:
        answer.append(color[b])

print(max(answer))
for a in answer:
    print(a)

# Fixed code:
import sys
input = sys.stdin.buffer.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
  
def make_tree(graph, root) -> (list, list, list):
    INF = 10 ** 15
    dist = [INF] * len(graph)
    parent = [-1] * len(graph)
    stack = [root]
    dist[root] = 0
    order = []
    parent[root] = root
    while stack:
        s = stack.pop()
        order.append(s)
        for g in graph[s]:
            if dist[g] > dist[s] + 1:
                dist[g] = dist[s] + 1
                parent[g] = s
                stack.append(g)
    return dist, parent, order
    
dist, parent, order = make_tree(graph, 1)

color = [-1] * (N + 1)
for s in order:
    ng = color[s]
    c = 1
    for g in graph[s]:
        if parent[s] == g:
            continue
        if c == ng:
            c += 1
        color[g] = c
        c += 1

answer = []
for a, b in AB:
    if parent[a] == b:
        answer.append(color[a])
    else:
        answer.append(color[b])

print(max(answer))
for a in answer:
    print(a)
# Buggy code:
N = int(input())
E = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split(' '))
    E[a].append((b,i))
    E[b].append((a,i))
K = max(len(e) for e in E)
print(K)
ans = [-1]*(N-1)
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u != p:
            if col == p_col:
                col += 1
            ans[idx] = col
            dfs(u, v, col)
            col += 1
dfs()
for i in ans[1:]:
    print(i)

# Fixed code:
import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split(' '))
    E[a].append((b, i))
    E[b].append((a, i))
K = max(len(e) for e in E)
print(K)
ans = [-1] * (N - 1)


def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u != p:
            if col == p_col:
                col += 1
            ans[idx] = col
            dfs(u, v, col)
            col += 1


dfs()
for i in ans:
    print(i)
# Buggy code:
words = lambda t : list(map(t, input().split()))
n = int(input())

vs = [[] for i in range(n)]
for i in range(n-1):
    s,e = words(int)
    vs[s-1].append(e-1)

import queue
q = queue.Queue()
q.put(0)
color = [0] * n
color[0] = 1
while not q.empty():
    v = q.get()
    cur_c = 1
    for c in vs[v]:
        if color[v] == cur_c:
            cur_c +=1
        color[c] = cur_c
        cur_c += 1
        q.put(c)

for i in range(n):
    print(color[i])


# Fixed code:
words = lambda t : list(map(t, input().split()))
n = int(input())

vs = [[] for i in range(n)]
for i in range(n-1):
    s,e = words(int)
    vs[s-1].append((e-1,i))

import queue
q = queue.Queue()
q.put(0)
color = [0] * (n-1)
color_par = [0] * (n)
color_par[0] = -1
while not q.empty():
    v = q.get()
    cur_c = 1
    for (c,i) in vs[v]:
        if color_par[v] == cur_c:
            cur_c +=1
        color[i] = cur_c
        color_par[c] = cur_c
        cur_c += 1
        q.put(c)

print(max(color))
for i in range(n-1):
    print(color[i])
# Buggy code:
# coding: utf-8
# Here your code !

import sys
sys.setrecursionlimit(10**6)
N = int(input())
v = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    v[a].append([b,i])
    print(v)
 
ans = [None] * (N-1)
 
def decide_colord(cur,color):
    cnt = 1
    for (to,j)in v[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        decide_colord(to,cnt)
        cnt += 1
decide_colord(0,0)
print(max(ans))
[print(a) for a in ans]

# Fixed code:
# coding: utf-8
# Here your code !

import sys
sys.setrecursionlimit(10**6)
N = int(input())
v = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    v[a].append([b,i])
 
ans = [None] * (N-1)
 
def decide_colord(cur,color):
    cnt = 1
    for (to,j)in v[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        decide_colord(to,cnt)
        cnt += 1
decide_colord(0,0)
print(max(ans))
[print(a) for a in ans]
# Buggy code:
from collections import deque

if __name__ == "__main__":
	N = int(input())
	AB = []
	for _ in range(N - 1):
		a, b = map(int, input().split())
		AB.append((a, b))

	graph = [[] for _ in range(N + 1)]
	for a, b in AB:
		graph[a].append(b)
		graph[b].append(a)

	root = 1
	parent = [0] * (N + 1)
	order = []
	Stack = deque()
	# make ordered tree
	while Stack:
		x = Stack.pop()
		order.append(x)
		for y in graph[x]:
			if parent[x] == y:
				continue
			parent[y] = x
			Stack.append(y)

	# assign color
	color = [-1] * (N + 1)
	for x in order:
		ng = color[x] # cannot assign the color of edge(x, parent[x])
		c = 1
		for y in graph[x]:
			if parent[x] == y:
				continue
			if c == ng:
				c += 1
			color[y] = c
			c += 1

	answer = []
	for a, b in AB:
		if parent[a] == b:
			answer.append(color[a])
		else:
			answer.append(color[b])
	K = max(answer)
	print(K)
	print('\n'.join(map(str, answer)))


# Fixed code:
from collections import deque

if __name__ == "__main__":
	N = int(input())
	AB = []
	for _ in range(N - 1):
		a, b = map(int, input().split())
		AB.append((a, b))

	graph = [[] for _ in range(N + 1)]
	for a, b in AB:
		graph[a].append(b)
		graph[b].append(a)

	root = 1
	parent = [0] * (N + 1)
	order = []
	stack = [root]
	# make ordered tree
	while stack:
		x = stack.pop()
		order.append(x)
		for y in graph[x]:
			if parent[x] == y:
				continue
			parent[y] = x
			stack.append(y)

	# assign color
	color = [-1] * (N + 1)
	for x in order:
		ng = color[x] # cannot assign the color of edge(x, parent[x])
		c = 1
		for y in graph[x]:
			if parent[x] == y:
				continue
			if c == ng:
				c += 1
			color[y] = c
			c += 1

	answer = []
	for a, b in AB:
		if parent[a] == b:
			answer.append(color[a])
		else:
			answer.append(color[b])
	K = max(answer)
	print(K)
	print('\n'.join(map(str, answer)))
# Buggy code:
from collections import deque

def bfs(idx,k):
  q = deque()
  visited[idx] = True
  q.append(idx)
  color = 0
  while q:
    r = q.pop()
    for n in graph[r].keys():
      if not visited[n]:
        if color not in graph[r].values():
          graph[r][n] = color
          graph[n][r] = color
          color = (color+1)%k
        else:
          color = (color+1)%k
          graph[r][n] = color
          graph[n][r] = color
          color = (color+1)%k
        visited[n] = True
        q.append(n)

        
N = int(input())
graph = {}
visited = [False]*(N+1)
for i in range(N+1):
  graph[i] = {}
ab = []
for i in range(N-1):
  a,b = map(int,input().split())
  ab.append((a,b))
  graph[a][b] = -1
  graph[b][a] = -1
  
k = 0
for i in range(1,N+1):
  k = max(k,len(graph[i]))

bfs(1,k)
print(k)
for i in range(N-1):
  a,b = ab[i]
  print(graph[a][b]+1)

  


  


# Fixed code:
from collections import deque

def bfs(idx,k,colored):
  q = deque()
  visited[idx] = True
  q.append(idx)
  while q:
    r = q.pop()
    color = 0
    for n in graph[r].keys():
      if not visited[n]:
        if color == colored[r]: color+=1
        colored[n] = color
        graph[r][n] = color
        graph[n][r] = color
        color += 1

        visited[n] = True
        q.append(n)

        
N = int(input())
graph = {}
colored = [-1]*(N+1)
visited = [False]*(N+1)
for i in range(N+1):
  graph[i] = {}
ab = []
for i in range(N-1):
  a,b = map(int,input().split())
  ab.append((a,b))
  graph[a][b] = -1
  graph[b][a] = -1
  
k = max([len(graph[i]) for i in range(1,N+1)])

bfs(1,k,colored)
print(k)
for a,b in ab:
  print(graph[a][b]+1)
# Buggy code:
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    
    node = [0]*(n-1)
    next_node = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        node[i] = (a-1, b-1)
        next_node[a-1].append(b-1)
        next_node[b-1].append(a-1)
    
    ans = 0
    for i in range(n):
        if ans < len(next_node[i]):
            ans = len(next_node[i])
    print(ans)
    
    not_yet = deque([])
    already = [False]*n
    parent = [1]*n
    ans_list = dict()
    k = 1
    
    already[0] = True
    for value in next_node[0]:
        not_yet.append(value)
        ans_list[(0, value)] = k
        parent[value] = k
        already[value] = True
        k += 1
    
    
    while not_yet:
        k = 1
        key = not_yet.popleft()
        for value in next_node[key]:
            if already[value]:
                continue
            if k == parent[key]:
                k += 1
            parent[value] = k
            p, q = min([key, value]), max([key, value])
            ans_list[(p, q)] = k
            k += 1
            for sub in next_node[value]:
                if already[sub]:
                    continue
                not_yet.append(sub)
                already[sub] = True
    for value in node:
        print(ans_list[value])


if __name__ == "__main__":
    main()

# Fixed code:
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    
    node = [0]*(n-1)
    next_node = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        node[i] = (a-1, b-1)
        next_node[a-1].append(b-1)
        next_node[b-1].append(a-1)
    
    ans = 0
    for i in range(n):
        if ans < len(next_node[i]):
            ans = len(next_node[i])
    print(ans)
    
    not_yet = deque([])
    already = [False]*n
    parent = [0]*n
    ans_list = dict()
    k = 1
    
    already[0] = True
    for value in next_node[0]:
        not_yet.append(value)
        ans_list[(0, value)] = k
        parent[value] = k
        already[value] = True
        k += 1
    
    
    while not_yet:
        k = 1
        key = not_yet.popleft()
        for value in next_node[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            if k == parent[key]:
                k += 1
            parent[value] = k
            p, q = min([key, value]), max([key, value])
            ans_list[(p, q)] = k
            k += 1
            
    
    for value in node:
        print(ans_list[value])


if __name__ == "__main__":
    main()
# Buggy code:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N = int(input())
ab = [list(map(int,input().split())) for i in range(N-1)]
E = [[] for _ in range(N+1)]
for i in range(N-1):
    E[ab[i][0]].append(ab[i][1])
color_num = max(len(E[i]) for i in range(N+1))
print(color_num)
color = [0]*(N+1)

start = 1
q = deque([start])
while(q):
    v = q.pop()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == color[v])
        color[u] = c
        q.append(u)
for i in range(N-1):
    print(color[ab[i][1]])

# Fixed code:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N = int(input())
ab = [list(map(int,input().split())) for i in range(N-1)]
E = [[] for _ in range(N+1)]
for i in range(N-1):
    E[ab[i][0]].append(ab[i][1])
color = [0]*(N+1)

start = 1
q = deque([start])
while(q):
    v = q.pop()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == color[v])
        color[u] = c
        q.append(u)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])
# Buggy code:
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

n = int(input())
ab = [list(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]

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

p = [0] * n
c = [0] * n
d = [0] * n

for a, b in ab:
    e[a].append(b)
    e[b].append(a)

me = 0

q = [0]
p[0] = -1

while q:
    x = q.pop()
    temp = c[x]
    color = 1
    me = max(me, len(e[x]))
    for y in e[x]:
        if color == temp:
            color += 1
        if d[y] == 0:
            q.append(y)
            c[y] = color
            p[y] = x
        color += 1
    d[x] = 1

print(me)

for a, b in ab:
    if p[a] == b:
        print(c[a])
    else:
        print(c[b])

# Fixed code:
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

n = int(input())
ab = [list(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]

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

p = [0] * n
c = [0] * n
d = [0] * n

for a, b in ab:
    e[a].append(b)
    e[b].append(a)

me = 0

q = [0]
p[0] = -1

while q:
    x = q.pop()
    temp = c[x]
    color = 1
    me = max(me, len(e[x]))
    #print(x, temp)
    for y in e[x]:
        if color == temp:
            color += 1
        if d[y] == 0:
            q.append(y)
            c[y] = color
            p[y] = x
            color += 1
    d[x] = 1

#print(c)
#print(p)

print(me)

for a, b in ab:
    if p[a] == b:
        print(c[a])
    else:
        print(c[b])
# Buggy code:
from sys import setrecursionlimit

setrecursionlimit(100000)

N = int(input())

adj = [list() for _ in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    adj[a].append((b,i))
    adj[b].append((a,i))

C,s = max((len(l),v) for v,l in enumerate(adj))

res = [None]*(N-1)

def rec(v, used):
    global res
    c = 0
    for u,i in adj[v]:
        if c == used:
            c += 1
        if res[i] is None:
            res[i] = c
            rec(u, c)
        c += 1
rec(s, -1)
print(C)
for c in res:
    print(c+1)


# Fixed code:
from sys import setrecursionlimit

setrecursionlimit(100000)

N = int(input())

adj = [list() for _ in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    adj[a].append((b,i))
    adj[b].append((a,i))


res = [None]*(N-1)

C = max(len(l) for l in adj)

def rec(v, used):
    global res
    c = 0
    for u,i in adj[v]:
        if c == used:
            c += 1
        if res[i] is None:
            res[i] = c
            rec(u, c)
            c += 1
rec(0, -1)
print(C)
for c in res:
    print(c+1)
# Buggy code:
from collections import deque
n=int(input())
g=[[] for _ in range(n+1)]
e=[]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a].append(b)
    e.append(b)

q=deque([0])

color=[0 for _ in range(n)]
while(len(q)>0):
    ei=q.popleft()
    c=1
    for x in g[ei]:
        if c == color[ei]:
            c+=1

        color[x]=c
        c+=1
        q.append(x)

print(max(color))
for i in e:
    print(color[i])

# Fixed code:
from collections import deque
n=int(input())
g=[[] for _ in range(n+1)]
e=[]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    e.append(b-1)

q=deque([0])

color=[0 for _ in range(n)]
while(len(q)>0):
    ei=q.popleft()
    c=1
    for x in g[ei]:
        if c == color[ei]:
            c+=1

        color[x]=c
        c+=1
        q.append(x)

print(max(color))
for i in e:
    print(color[i])