def has_cycles(graph):
    """ Checks whether the graph has a cycle
    :param graph: instance of class Graph.
    :return: bool
    """
    for n1, n2, d in graph.edges():
        if n1 == n2:
            return True
        if graph.depth_first_search(start=n2, end=n1):
            return True
    return False