def laser_mirrors(rows, cols, mir):
    # construire les structures
    n = len(mir)
    orien = [None] * (n + 2)
    orien[n] = 0  # orientations arbitraires pour les ouvertures
    orien[n + 1] = 0
    succ = [[None for direc in range(4)] for i in range(n + 2)]
    L = [(mir[i][0], mir[i][1], i) for i in range(n)]
    L.append((0, -1, n))                  # entrée
    L.append((0, cols, n + 1))              # sortie
    last_r = None
    for (r, c, i) in sorted(L):           # balayage par ligne
        if last_r == r:
            succ[i][LEFT] = last_i
            succ[last_i][RIGHT] = i
        last_r, last_i = r, i
    last_c = None
    for (r, c, i) in sorted(L, key=lambda tup_rci: (tup_rci[1], tup_rci[0])):
        if last_c == c:                   # balayage par colonne
            succ[i][UP] = last_i
            succ[last_i][DOWN] = i
        last_c, last_i = c, i
    if solve(succ, orien, n, RIGHT):      # exploration
        return orien[:n]
    else:
        return None
# snip}


# snip{ laser-miroir-exploration
Orienting mirrors to allow reachability by laser beam
dataset/ETHPy150Open jilljenn/tryalgo/tryalgo/laser_mirrors.py/laser_mirrors