You are viewing a single comment's thread. Return to all comments →
def treeLength(tree, node, count): if tree.get(node): for n in tree[node]: count = treeLength(tree, n, count + 1) return count def evenForest(t_nodes, t_edges, t_from, t_to): graph = {} for i in range(t_edges): if t_to[i] in graph: graph[t_to[i]].append(t_from[i]) else: graph[t_to[i]] = [t_from[i]] count = 0 for e in graph: for n in graph[e]: length = treeLength(graph, n, 1) if not length % 2: count += 1 return count
Seems like cookies are disabled on this browser, please enable them to open this website
Even Tree
You are viewing a single comment's thread. Return to all comments →