def find_cycle(graph):
    """find a cycle in an undirected graph

    :param graph: undirected graph in listlist or listdict format
    :returns: list of vertices in a cycle or None
    :complexity: `O(|V|+|E|)`
    """
    n = len(graph)
    prec = [None] * n
    for u in range(n):
        if prec[u] is None:
            S = [u]
            prec[u] = u
            while S:
                u = S.pop()
                for v in graph[u]:
                    if v != prec[u]:
                        if prec[v] is not None:
                            cycle = [v, u]
                            while u != prec[v] and u != prec[u]:
                                u = prec[u]
                                cycle.append(u)
                            return cycle
                        else:
                            prec[v] = u
                            S.append(v)
    return None
