Transaction deadlock detection

Write codeHard35 minOracle style

Your task

Detect whether a set of transactions is deadlocked given a wait-for graph. Input is a list of (a, b) edges meaning transaction a is waiting for a resource held by transaction b. A deadlock exists if and only if this directed graph contains a cycle. Return True if any cycle exists, else False. Node labels are arbitrary hashable values; an edge may appear more than once; self-loops (a waits for itself) count as a cycle. The edge list may be empty.

Examples

has_deadlock(edges: list[tuple]) -> bool
Example 1
Inputhas_deadlock([["t1", "t2"], ["t2", "t3"], ["t3", "t1"]])
OutputTrue