def find_roots(self, v, visited):
    ''' @return: False, if failed to find the root,
                 starting with vertex 'v' and past path 'visited'
                 True, otherwise.
    '''
    adjs = self.inv_g.adjacents(v)
    if not adjs:
      self.roots.add(v)
      return True
    if len(adjs)>1:
      return False    # With bifurcation
    else:
      u = adjs[0]
      visited[v] = True
      if not visited.get(u, False):
        return self.find_roots(u, visited)
      else:
        return False  # With cycle
    return True
 @return: False, if failed to find the root,
                 starting with vertex 'v' and past path 'visited'
                 True, otherwise.
    
recipes/Python/576912_A_Tree_Finder/recipe-576912.py