def cyclomatic_complexity2(control_flow_graph):
  """Computes the cyclomatic complexity of a program from its cfg."""
  # Assumes a single connected component.
  p = 1  # num_connected_components
  e = sum(len(block.exits_from_end) for block in control_flow_graph.blocks)
  n = len(control_flow_graph.blocks)
  return e - n + 2 * p