from itertools import product

# Our own miniature board, not Covert Action source code.
# Each replacement chip selects one output wire.
chips = {
    "entry": ("phone", "bypass"),
    "bypass": ("alarm", "tap"),
}

def trace(settings):
    reached, pending = set(), ["entry"]
    while pending:
        node = pending.pop()
        if node in reached:
            continue
        reached.add(node)
        if node in settings:
            pending.append(settings[node])
    return reached

solutions = []
for outputs in product(*chips.values()):
    settings = dict(zip(chips, outputs))
    reached = trace(settings)
    if "tap" in reached and not {"phone", "alarm"} & reached:
        solutions.append(settings)

assert len(solutions) == 1
assert "alarm" in trace({"entry": "bypass", "bypass": "alarm"})
assert "phone" in trace({"entry": "phone", "bypass": "tap"})
print(solutions[0])
