def precedes(layers, n1, n2):
    """
    Helper function to determine whether node n1 is in
    a layer that immediately precedes the layer of node n2.
    """
    i = [k for k in range(len(layers)) if n1 in layers[k]][0]
    j = [k for k in range(len(layers)) if n2 in layers[k]][0]

    return i + 1 == j