You are viewing a single comment's thread. Return to all comments →
it's just not best
def evenForest(t_nodes, t_edges, t_from, t_to): kq = 0 d = {} r = {} p = [] for i in range(t_edges): if t_to[i] not in d: d[t_to[i]] = [t_from[i]] r[t_to[i]] = 1 else: d[t_to[i]].append(t_from[i]) for i in d: j = 0 while j < len(d[i]): if d[i][j] not in d: d[i].remove(d[i][j]) r[i] += 1 else: j += 1 if not d[i]: p.append(i) for i in p: del d[i] def dfs(node, visited, graph): visited.add(node) for neighbor in graph.get(node, []): if neighbor not in visited: dfs(neighbor, visited, graph) return visited for i in d: for j in d[i]: vi = set() vi = dfs(j, vi, d) t = 0 for j in vi: t += r[j] if not 1 & t: kq += 1 return kq
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 →
it's just not best