Problem:


Score : 400 points

Problem Statement

Given is a tree G with N vertices.
The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.

Consider painting the edges in G with some number of colors.
We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.

Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Constraints

 2 \le N \le 10^5

 1 \le a_i \lt b_i \le N

All values in input are integers.

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}

Output

Print N lines.

The first line should contain K, the number of colors used.

The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \le c_i \le K must hold.

If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.

Sample Input 1

3
1 2
2 3

Sample Output 1

2
1
2

Sample Input 2

8
1 2
2 3
2 4
2 5
4 7
5 6
6 8

Sample Output 2

4
1
2
3
4
1
1
2

Sample Input 3

6
1 2
1 3
1 4
1 5
1 6

Sample Output 3

5
1
2
3
4
5



Sample input:
3
1 2
2 3


Sample output:
2
1
2

Submission status: Runtime Error

Solution code:
class Node:
    nodes = {}

    @classmethod
    def get_root_node(cls):
        n = Node.nodes[next(iter(Node.nodes))]
        while True:
            if n.parent is None:
                return n
            else:
                n = n.parent

    @classmethod
    def largest_child(cls):
        r = 0
        for key, node in Node.nodes.items():
            if len(node.childs) > r:
                r = len(node.childs)
        return r

    @classmethod
    def dump_all_nodes(cls):
        for key, node in Node.nodes.items():
            print(str(node))

    @classmethod
    def get_instance(cls, id, parent):
        if id in Node.nodes:
            if Node.nodes[id].parent is None:
                Node.nodes[id].parent = parent
            return Node.nodes[id]
        else:
            return Node(id, parent)

    def __init__(self, id, parent):
        self.id = id
        self.parent = parent # None if root Node
        self.parent_edge_color = None
        self.childs = {}
        Node.nodes[id] = self
        self.used_color = []

    def __str__(self):
        x = self.parent.id if self.parent else "None"
        return f"id: {self.id}, parent: {x}, parent_edge_color: {self.parent_edge_color} ,num_child {len(self.childs)}"

    def append_child(self, node):
        self.childs[node.id] = node

    def set_parent_edge_color(self, c):
        print(c)
        self.parent_edge_color = c

    def color_childs(self):
        c = 0
        for key, child_node in self.childs.items():
            if c == self.parent_edge_color:
                c += 1
            child_node.parent_edge_color = c
            c += 1
            child_node.color_childs()

N = int(input())

Edges = []
Edges_color = []
for i in range(N-1):
    edge = list(map(int, input().split()))
    Edges.append(edge)


for edge in Edges:
    pnode = Node.get_instance(edge[0], None)
    cnode = Node.get_instance(edge[1], pnode)
    pnode.append_child(cnode)

K = Node.largest_child() + 1
print(K)

root = Node.get_root_node()

root.color_childs()
#Node.dump_all_nodes() #ok

for edge in Edges:
    print(Node.get_instance(edge[1], edge[0]).parent_edge_color)

Submission status: Runtime Error

Solution code:
N = int(input())
v = [[] for _ in range(N)]
visited = [False for _ in range(N)]
ret = [1 for _ in range(N - 1)]

for i in range(N - 1):
	a, b = map(int, input().split())
	v[a - 1].append([b - 1, i])
	v[b - 1].append([a - 1, i])
	
color_max = 0
for lst in v:
	color_max = max(color_max, len(lst))
print(color_max)

def dfs(cur, color):
	visited[cur] = True
	now_color = 1
	for i in range(len(v[cur])):
		adj, num = v[cur][i]
		if not visited[adj]:
			if now_color == color:
				now_color += 1
			ret[num] = now_color
			dfs(adj, now_color)
			now_color += 1

dfs(0, 0)

for i in ret:
	print(i)

Submission status: Runtime Error

Solution code:
N = int(input())
v = [[] for _ in range(N)]
visited = [False for _ in range(N)]
ret = [None for _ in range(N - 1)]

for i in range(N - 1):
	a, b = map(int, input().split())
	v[a - 1].append([b - 1, i])
	v[b - 1].append([a - 1, i])
	
color_max = 0
for lst in v:
	color_max = max(color_max, len(lst))
print(color_max)

def dfs(cur, color):
	visited[cur] = True
	now_color = 1
	for i in range(len(v[cur])):
		adj, num = v[cur][i]
		if not visited[adj]:
			if now_color == color:
				now_color += 1
			ret[num] = now_color
			dfs(adj, now_color)
			now_color += 1

dfs(0, 0)

for i in ret:
	print(i)

Submission status: Runtime Error

Solution code:
N = int(input())
v = [[] for _ in range(N)]
visited = [False for _ in range(N)]
ret = [None for _ in range(N - 1)]

for i in range(N - 1):
	a, b = map(int, input().split())
	v[a - 1].append([b - 1, i])
	v[b - 1].append([a - 1, i])
	
color_max = 0
for lst in v:
	color_max = max(color_max, len(lst))
print(color_max)

def dfs(cur, color):
	old_color = color
	visited[cur] = True
	for i in range(len(v[cur])):
		adj, num = v[cur][i]
		if not visited[adj]:
			color += 1
			if color == color_max + 1:
				color = 1
			ret[num] = color
			dfs(adj, color)

dfs(0, 0)

for i in ret:
	print(i)

Submission status: Runtime Error

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
import math
from itertools import permutations, combinations
from collections import deque

sys.setrecursionlimit(10**7)
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)
edges = [[] for _ in range(N)]
for abi in ab:
    a, b = abi[0], abi[1]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

K = max(list(map(len, edges)))
print(K)

adjm = [[0]*N for _ in range(N)]

Q = deque()
for edge in edges[0]:
    Q.append((0, edge))

while Q:
    labels = set(i for i in range(1, K+1))
    points = Q.popleft()
    p0, p1 = points

    set1 = set(adjm[p0])
    can_use_labels = labels - set1
    use_label = can_use_labels.pop()

    adjm[p0][p1] = use_label
    adjm[p1][p0] = use_label

    for p in edges[p1]:
        if p != p0:
            Q.append((p1, p))

for abi in ab:
    a, b = abi[0], abi[1]
    print(adjm[a-1][b-1])

Submission status: Runtime Error

Solution code:
N = int(input())
v = [[] for _ in range(N)]
visited = [False for _ in range(N)]
output_order = []

for _ in range(N - 1):
	a, b = map(int, input().split())
	v[a - 1].append(b - 1)
	v[b - 1].append(a - 1)
	output_order.append([a - 1, b - 1])
	
color_max = 0
for lst in v:
	color_max = max(color_max, len(lst))
print(color_max)

def dfs(cur, color):
	old_color = color
	visited[cur] = True
	for i in range(len(v[cur])):
		adj = v[cur][i]
		if not visited[adj]:
			color += 1
			if color == color_max + 1:
				color = 1
			a = [cur, adj]
			a.sort()
			output_order[output_order.index(a)] = color
			dfs(adj, color)

dfs(0, 0)

for res in output_order:
	print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
node = [[] for _ in range(n)]
edge = []
for i in range(n-1):
    a,b = map(lambda x:int(x)-1, input().split())
    edge.append((a,b))
    node[a].append(b)
    node[b].append(a)
k = max(len(i) for i in node)
print(k)
node = [set(range(1,k+1)) for _ in range(n)]
for i,j in edge:
    tmp = (node[i]&node[j]).pop()
    node[i].remove(tmp)
    node[j].remove(tmp)
    print(tmp)

Submission status: Runtime Error

Solution code:
n=int(input())
path_color=[None]*(n-1)
tree_path=[[] for x in range(n)]
path_num_to_edges=[]
tree_edge_flag=set()
for i in range(n-1):
    ai,bi=[int(x) -1 for x in input().split()]
    tree_path[ai].append((bi,i))
    tree_path[bi].append((ai,i))
    path_num_to_edges.append((ai,bi))

path_color[0]=1
from collections import deque
d=deque()
d.append(0)
while d:
    temp=d.pop()
    temp_color=path_color[temp]
    edges=path_num_to_edges[temp]
    for edge in edges:
        new_path_color=1
        if edge in tree_edge_flag:
            continue
        tree_edge_flag.add(edge)
        for other_edge,path_num in tree_path[edge]:
            if path_color[path_num]!=None:
                continue
            if other_edge in tree_edge_flag:
                continue
            tree_edge_flag.add(other_edge)
            if new_path_color==temp_color:
                new_path_color+=1
            path_color[path_num]=new_path_color
            new_path_color+=1
            d.append(path_num)


print(max(path_color))
for i in path_color:
    print(i)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    V = [set() for _ in range(N)]
    E = {}
    for j in range(N - 1):
        a, b = [int(i) - 1 for i in input().split()]
        V[a].add(j)
        V[b].add(j)
        E[(a, j)] = b
        E[(b, j)] = a
    C = [0] * (N - 1)
    clrs = max(len(i) for i in V)
    def color(n, p):
        for e in V[n]:
            if C[e] != 0:
                continue
            c = p + 1
            if c > clrs:
                c = 1
            C[e] = c
            color(E[(n, e)], c)
            p = c
    color(0, 0)
    print(clrs)
    for i in C:
        print(i)

main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    E = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) - 1 for i in input().split()]
        E[a].add(b)
        E[b].add(a)
    c = [0] * N
    clrs = max(len(i) for i in E)
    BAD = 1 << clrs - 1
    def color(n):
        t = set()
        for i in E[n]:
            t.add(c[i])
        for i in range(1, clrs + 1):
            if i in t:
                continue
            c[n] = i
            for j in E[n]:
                if c[j] == 0:
                    color(j)
            return
        raise
    color(0)
    print(clrs)
    for i in c:
        print(i)

main()

Submission status: Runtime Error

Solution code:
n = int(input())
sides = []
for i in range(n - 1):
    sides.append(list(map(int, input().split())))
    
sides

sides_color = {}
for i in sides:
    sides_color[tuple(i)] = 0
    

def get_color(a, b):
    if a > b:
        a, b = b, a
        
    return sides_color[(a,b)]

def set_color(a, b, c):
    if a > b:
        a, b = b, a
        
    sides_color[(a,b)] = c

n_nodes = max(sum(sides, []))
nodes = [[0] * (n_nodes + 1) for i in range((n_nodes + 1))]

for i in sides:
    nodes[i[0]][i[1]] = 1
    nodes[i[1]][i[0]] = 1

n_sides = list(map(sum, nodes))
nodes_sides = {}

for i in range(n_nodes + 1):
    nodes_sides[i] = n_sides[i]

score_sorted = sorted(nodes_sides.items(), key=lambda x:-x[1])

n_color = score_sorted[0][1]

for n, _ in score_sorted:
    color_used = list(range(1, n_color + 1))
    
    if n == 0:
        break
    for i in range(1, n_nodes + 1):
        if nodes[n][i] == 1:
            c = get_color(n, i)

            if c == 0:
                c = color_used[0]
                set_color(n, i, c)
            
            color_used.remove(c)

print(n_color)

for s in sides:
    print(sides_color[tuple(s)])

Submission status: Runtime Error

Solution code:
def kolorowe_grafy():
    N = wczytaj_liste()[0]
    lista_krawedzi = []
    listy_krawedzi = [[]]
    for i in range(N-1):
        lista_krawedzi.append(wczytaj_liste())
        listy_krawedzi.append([])
    for w1, w2 in lista_krawedzi: 
        listy_krawedzi[w1-1].append(w2)
        listy_krawedzi[w2-1].append(w1)
        
    do_przejrzenia = [1]
    kolory_zabronione = {1: 0}
    indeks_przegladanego = 0 
    kolor_tenczy = {}
    while indeks_przegladanego < len(do_przejrzenia): 
        aktualnie_przegladany = do_przejrzenia[indeks_przegladanego]
        kolor = 1
        if kolor == kolory_zabronione[aktualnie_przegladany]:
            kolor += 1
        for sasiad in listy_krawedzi[aktualnie_przegladany-1]: 
            if sasiad not in kolory_zabronione: 
                kolory_zabronione[sasiad] = kolor
                kolor_tenczy[(aktualnie_przegladany,sasiad)]=kolor
                kolor_tenczy[(sasiad,aktualnie_przegladany)]=kolor
                kolor += 1
                
                if kolor == kolory_zabronione[aktualnie_przegladany]:
                    kolor += 1
                do_przejrzenia.append(sasiad)
        indeks_przegladanego += 1
    maximum = 0
    for w1, w2 in lista_krawedzi:
        maximum = max(kolor_tenczy[(w1,w2)], maximum)
    print(maximum)
    for w1, w2 in lista_krawedzi:
        print(kolor_tenczy[(w1,w2)])
kolorowe_grafy()

Submission status: Runtime Error

Solution code:
def kolorowe_grafy():
    N = wczytaj_liste()[0]
    lista_krawedzi = []
    listy_krawedzi = [[]]
    for i in range(N-1):
        lista_krawedzi.append(wczytaj_liste())
        listy_krawedzi.append([])
    for w1, w2 in lista_krawedzi: 
        listy_krawedzi[w1-1].append(w2)
        listy_krawedzi[w2-1].append(w1)
        
    do_przejrzenia = [1]
    kolory_zabronione = {1: 0}
    indeks_przegladanego = 0 
    kolor_tenczy = {}
    while indeks_przegladanego < len(do_przejrzenia): 
        aktualnie_przegladany = do_przejrzenia[indeks_przegladanego]
        kolor = 1
        if kolor == kolory_zabronione[aktualnie_przegladany]:
            kolor += 1
        for sasiad in listy_krawedzi[aktualnie_przegladany-1]: 
            if sasiad not in kolory_zabronione: 
                kolory_zabronione[sasiad] = kolor
                kolor_tenczy[(aktualnie_przegladany,sasiad)]=kolor
                kolor_tenczy[(sasiad,aktualnie_przegladany)]=kolor
                kolor += 1
                
                if kolor == kolory_zabronione[aktualnie_przegladany]:
                    kolor += 1
                do_przejrzenia.append(sasiad)
        indeks_przegladanego += 1
    maximum = 0
    for w1, w2 in lista_krawedzi:
        maximum = max(kolor_tenczy[(w1,w2)], maximum)
    print(maximum)
    for w1, w2 in lista_krawedzi:
        print(kolor_tenczy[(w1,w2)])

kolorowe_grafy()

Submission status: Runtime Error

Solution code:
n=int(input())
s=[[]for i in range(n+1)]
t=[0]*(n-1)
for i in range(n-1):
    a,b=map(int,input().split())
    s[a-1].append([b-1,i])
def f(x,r):
    c=1
    for (i,j) in s[x]:
        if c==r:
            c+=1
        t[j]=c
        f(i,c)
        c+=1
f(0,0)
print(max(t))
for i in t:
    print(i)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys


def create_graph(N, a, b):
    g = {}
    for i in range(N-1):
        if a[i] in g:
            g[a[i]][b[i]] = 0
        else:
            g[a[i]] = {b[i]: 0}
        if b[i] in g:
            g[b[i]][a[i]] = 0
        else:
            g[b[i]] = {a[i]: 0}
    return g


def find_color(used, m):
    for i in range(1, m+1):
        if i not in used:
            return i
    return m+1


def dfs(g, p):
    for q in g[p].keys():
        # print(f"p:{p} q:{q} g:{g[p][q]}")
        if not g[p][q]:
            c = find_color(set([v for k, v in g[p].items() if v > 0]), len(g[p]))
            g[p][q] = c
            g[q][p] = c
            dfs(g, q)


def solve(N: int, a, b):
    g = create_graph(N, a, b)
    dfs(g, a[0])
    # print(g)
    m = 1
    for i in range(N-1):
        m = max(m, g[a[i]][b[i]])
    print(m)
    for i in range(N-1):
        print(g[a[i]][b[i]])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]for i in range(n)]
for i in range(n-1):
    c,d=map(int,input().split())
    a[c-1].append([d-1,i])
b=[0]*(n-1)
def f(x,y):
    r=1
    for (i,j) in a[x]:
        if r==y:
            r+=1
        b[j]=r
        f(i,r)
        r+=1
f(0,0)
print(max(b))
print(*b,sep="\n")

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]for i in range(n)]
for i in range(n-1):
    c,d=map(int,input().split())
    a[c-1].append([d-1,i])
b=[0]*(n-1)
def f(x,y):
    r=1
    for (i,j) in a[x]:
        if r==y:
            r+=1
        b[j]=r
        f(i,r)
        r+=1
f(0,0)
print(max(b))
print(*ans,sep="\n")

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]for i in range(n)]
for i in range(n-1):
    c,d=map(int,input().split())
    a[c-1].append([d-1,i])
b=[0]*(n-1)
def f(x,y):
    r=1
    for (i,j) in a[x]:
        if r==y:
            r+=1
        b[j]=r
        f(i,r)
        r+=1
f(0,0)
print(max(b))
for i in b:
    print(i)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]for i in range(n)]
for i in range(n-1):
    c,d=map(int,input().split())
    a[c-1].append([d-1,i])
c=[None]*(n-1)
def f(x,y):
    r=1
    for i in a[x]:
        if r==y:
            r+=1
        c[i[1]]=r
        f(i[0],r)
        r+=1
f(0,0)
print(max(c))
for i in c:
    print(i)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]for i in range(n)]
for i in range(n-1):
    c,d=map(int,input().split())
    a[c-1].append([d-1,i])
c=[0]*(n-1)
def f(x,y):
    r=1
    for i in a[x]:
        if r==y:
            r+=1
        c[i[1]]=r
        f(i[0],r)
        r+=1
f(0,0)
print(max(c))
for i in c:
    print(i)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]for i in range(n)]
for i in range(n-1):
    c,d=map(int,input().split())
    a[c-1].append([d-1,i])
c=[0]*(n-1)
def f(x,y):
    r=1
    for i in a[x]:
        if r==y:
            r+=1
        c[i[1]]=r
        f(i[0],r)
        r+=1
f(1,0)
print(max(c))
for i in c:
    print(i)

Submission status: Runtime Error

Solution code:
#ノードクラス
class Node():
    def __init__(self):
        self.name=-1
        self.parent=-1
        self.p_color=0
        self.child=[]
        self.c_color=[]
        self.type=-1
    

#木クラス
class Tree():
    
    
    #作成した瞬間、入力の数だけノードを作る。
    def __init__(self):
        self.tree=[None]
        self.list=[]
        self.node_n=int(input())
        for i in range(self.node_n):
            a=Node()
            a.name=i+1
            self.tree.append(a)
        for i in range(self.node_n-1):
            hen=[int(j) for j in input().split(" ")]
            self.list.append(hen)
            self.tree[hen[0]].child.append(self.tree[hen[1]])
            self.tree[hen[1]].parent=self.tree[hen[0]]
            
        for i in range(1,self.node_n+1):
            node=self.tree[i]
            if node.parent==-1:
                node.type="root"
            elif node.child==[]:
                node.type="leaf"
            else:
                node.type=="other"
        
    def getroot(self):
        return self.tree[1]
    def getleaf(self):
        leaf=[]
        for i in self.tree:
            if i.type=="leaf":
                leaf.append(i)
        return leaf
    
    def gettree(self):
        return self.tree[:]

    
        
    
    
#木の作成
tree=Tree()


#使った色リスト
colorlist=[]


#調べたリスト
# checklist=tree.gettree()
# checklist.pop(0)
# checklist.pop(0)
# print("checklist",[i.name for i in checklist])

colvar=[tree.node_n-int(i) for i in range(tree.node_n) ]
node=tree.getroot()




def haihai(node):
#     print("node",node.name)
    parentcolor=node.p_color
    children=node.child
    if children==[]:
        pass
    else:
#         print("children",[i.name for i in children])
        childcolor=colvar.copy()
        if parentcolor in childcolor:
            childcolor.remove(parentcolor)
        for child in children:
#             print("childname",child.name)
#             checklist.remove(child)
            color=childcolor.pop()
            child.p_color=color
            if color not in colorlist :
                colorlist.append(color)
            haihai(child)
            

haihai(node)

# print(colorlist)

print(len(colorlist))


for j in [tree.tree[i[1]].p_color for i in tree.list]:
    print(j)

Submission status: Runtime Error

Solution code:
#ノードクラス
class Node():
    def __init__(self):
        self.name=-1
        self.parent=-1
        self.p_color=0
        self.child=[]
        self.c_color=[]
        self.type=-1
    

#木クラス
class Tree():
    
    
    #作成した瞬間、入力の数だけノードを作る。
    def __init__(self):
        self.tree=[None]
        self.list=[]
        self.node_n=int(input())
        for i in range(self.node_n):
            a=Node()
            a.name=i+1
            self.tree.append(a)
        for i in range(self.node_n-1):
            hen=[int(j) for j in input().split(" ")]
            self.list.append(hen)
            self.tree[hen[0]].child.append(self.tree[hen[1]])
            self.tree[hen[1]].parent=self.tree[hen[0]]
            
        for i in range(1,self.node_n+1):
            node=self.tree[i]
            if node.parent==-1:
                node.type="root"
            elif node.child==[]:
                node.type="leaf"
            else:
                node.type=="other"
        
    def getroot(self):
        return self.tree[1]
    def getleaf(self):
        leaf=[]
        for i in self.tree:
            if i.type=="leaf":
                leaf.append(i)
        return leaf
    
    def gettree(self):
        return self.tree[:]

    
        
    
    
#木の作成
tree=Tree()


#使った色リスト
colorlist=[]


#調べたリスト
# checklist=tree.gettree()
# checklist.pop(0)
# checklist.pop(0)
# print("checklist",[i.name for i in checklist])

colvar=[tree.node_n-int(i) for i in range(tree.node_n) ]
node=tree.getroot()




def haihai(node):
    print("node",node.name)
    parentcolor=node.p_color
    children=node.child
    if children==[]:
        pass
    else:
        print("children",[i.name for i in children])
        childcolor=colvar.copy()
        if parentcolor in childcolor:
            childcolor.remove(parentcolor)
        for child in children:
            print("childname",child.name)
#             checklist.remove(child)
            color=childcolor.pop()
            child.p_color=color
            if color not in colorlist :
                colorlist.append(color)
            haihai(child)
            

haihai(node)

print(colorlist)

print(len(colorlist))


for j in [tree.tree[i[1]].p_color for i in tree.list]:
    print(j)

Submission status: Runtime Error

Solution code:


from collections import defaultdict


def main(V):
    t = defaultdict(lambda: set())
    res = []
    for a, b in V:
        for i in range(1, len(V)):
            if i not in t[a] and i not in t[b]:
                res.append(i)
                t[a].add(i)
                t[b].add(i)
                break
    print(max(res))
    for i in res:
        print(i)


if __name__ == "__main__":
    N = int(input(''))
    V = []
    for i in range(1, N):
        V.append(tuple(map(int, input('').split(' '))))
    main(V)

Submission status: Runtime Error

Solution code:
n=int(input())
colors={}

#print("####################")

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

colors[1]=[1]
colors[2]=[1]

resultCorors=[1]

kindOfcolor=1

for item in inputA[1:]:
    #print(i,colors)
    pati, chil = item[0],item[1]
    if chil not in colors:
        colors[chil]=[]

    temp=set(colors[pati])|set(colors[chil])
    for j in range(1,n+2):
        if j not in temp:
            colors[chil].append(j)
            colors[pati].append(j)
            resultCorors.append(j)
            kindOfcolor=max(kindOfcolor,j)
            break

print(kindOfcolor)
for item in resultCorors:
    print(item)

Submission status: Runtime Error

Solution code:
n=int(input())
colors={}

#print("####################")

pati,chil=map(int,input().split())
colors[pati]=[1]
colors[chil]=[1]
print(1)

for i in range(n-2):
    #print(i,colors)
    pati, chil = map(int, input().split())
    if chil not in colors:
        colors[chil]=[]

    temp=set(colors[pati])|set(colors[chil])
    for j in range(1,n+2):
        if j not in temp:
            print(j)
            colors[chil].append(j)
            colors[pati].append(j)
            break

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

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

ans = [None]*(N-1)
def rec(cur, color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1

rec(0,0)
print(max(ans))
[print(a) for a in ans]

Submission status: Runtime Error

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

ans = [None]*(N-1)
def rec(cur, color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1

rec(0,0)
print(max(ans))
[print(a) for a in ans]

Submission status: Runtime Error

Solution code:
n=int(input())
a=[[]for i in range(n+1)]
for i in range(n-1):
    c,d=map(int,input().split())
    a[c].append([d,i])
c=[0]*(n-1)
def f(x,y):
    r=1
    for i in a[x]:
        if r==y:
            r+=1
        c[i[1]]=r
        f(i[0],r)
        r+=1
f(1,0)
print(max(c))
for i in c:
    print(i)

Submission status: Runtime Error

Solution code:
#ノードクラス
class Node():
    def __init__(self):
        self.name=-1
        self.parent=-1
        self.p_color=0
        self.child=[]
        self.c_color=[]
        self.type=-1
    

#木クラス
class Tree():
    
    
    #作成した瞬間、入力の数だけノードを作る。
    def __init__(self):
        self.tree=[None]
        self.list=[]
        self.node_n=int(input())
        for i in range(self.node_n):
            a=Node()
            a.name=i+1
            self.tree.append(a)
        for i in range(self.node_n-1):
            hen=[int(j) for j in input().split(" ")]
            self.list.append(hen)
            self.tree[hen[0]].child.append(self.tree[hen[1]])
            self.tree[hen[1]].parent=self.tree[hen[0]]
            
        for i in range(1,self.node_n+1):
            node=self.tree[i]
            if node.parent==-1:
                node.type="root"
            elif node.child==[]:
                node.type="leaf"
            else:
                node.type=="other"
        
    def getroot(self):
        return self.tree[1]
    def getleaf(self):
        leaf=[]
        for i in self.tree:
            if i.type=="leaf":
                leaf.append(i)
        return leaf
    
    def gettree(self):
        return self.tree

    
        
    
    
#木リストにノードを入れる
tree=Tree()


#使った色リスト
colorlist=[]


#調べたリスト
checklist=tree.gettree()
checklist=checklist[:]
checklist.pop(0)
checklist.pop(0)
# print("checklist",[i.name for i in checklist])

colvar=[len(checklist)-int(i) for i in range(len(checklist)) ]
node=tree.getroot()




def haihai(node):
#     print("node",node.name)
    parentcolor=node.p_color
    children=node.child
    if children==[]:
        pass
    else:
#         print("children",[i.name for i in children])
        childcolor=colvar[:]
        if parentcolor in childcolor:
            childcolor.remove(parentcolor)
        for child in children:
#             print("childname",child.name)
            checklist.remove(child)
            color=childcolor.pop()
            child.p_color=color
            if color not in colorlist :
                colorlist.append(color)
            haihai(child)
            

# print(colorlist)
haihai(node)

# print(colorlist)

print(len(colorlist))


for j in [tree.tree[i[1]].p_color for i in tree.list]:
    print(j)

Submission status: Runtime Error

Solution code:
N = int(input())
A, B = map(int, input().split())
for i in range(N):
  if A > B:
    ans = (A - B) * N
  else if A == B:
    ans = (A + B) * N
  else if A < B:
    ans = (B - A) * N
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [[] for _ in range(N+1)]
ans = [0 for _ in range(N-1)]
m = 1
for i in range(N-1):
    a,b = map(int,fi.input().split())
    r = m + 1
    for j in range(1,m+1):
        if j in s[a] or j in s[b]:
            continue
        else:
            r = j
            break
    s[a].append(r)
    s[b].append(r)
    ans[i] = r
    if r > m:
        m = r
print(m)
for i in range(N-1):
    print(ans[i])

Submission status: Runtime Error

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


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,-1)
print(*clist)

Submission status: Runtime Error

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


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,-1)
for i in range(n-1):
    print(clist[i])

Submission status: Runtime Error

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


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color =1
	    for next,id in ki[now]:
	    	    
                     
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    color+=1
	    	    
dfs(0,0)
for i in range(n-1):
    print(clist[i])

Submission status: Runtime Error

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


a=[0]*n
for i in range(n):
	    a[i]= len(ki[i])
print(max(a))
clist=[-1]*(n-1)
visited=[[0]for i in range(n)]
def dfs(now,last,ban_color=-1):
	    color = 1
	    for next,id in ki[now]:
	    	    if next == last:continue
	    	    if color == ban_color:
	    	    	    color+=1
	    	    clist[id] = color
	    	    dfs(next,now,color)
	    	    
	    	    
	    	    
dfs(0,0)
for i in range(n-1):
    print(clist[i])

Submission status: Runtime Error

Solution code:
n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)
for i in range(n-1):
  a[i],b[i]=map(int,input().split())
  
lis=[[0 for i in range(n)] for j in range(n)]
for i in range(n-1):
  lis[a[i]][b[i]]=1
  lis[b[i]][a[i]]=1

for i in range(n-1):
	num=sum(lis[i])
    ans=max(num,ans)
print(ans)