• + 0 comments
    tree = {}
        for i in range(0, len(t_from)):
            n1, n2 = t_from[i], t_to[i]
            tree[n1] = tree.get(n1, []) + [n2]
            tree[n2] = tree.get(n2, []) + [n1]
        
        cuts = 0 
        visited = set()
        
        def dfs_helper(node, visited):
            nonlocal cuts
            if node in visited: return 0
            elif tree.get(node, False) is False: return 0
            visited.add(node)
            count = 1
            for child in tree[node]:
                child_count = dfs_helper(child, visited)
                if child_count == 0: continue
                elif child_count % 2 == 0:
                    cuts += 1
                else:
                    count += child_count
            return count
    
        dfs_helper(1, visited)
        return cuts