Resources have a single instance. Input lines (any order) until the end of input:
holds P R— process P holds resource R;waits P R— process P waits for resource R;cost P c— the cost of aborting P (default 0).
- Build the wait-for graph: for each
waits P R(in input order) where R is held by another process Q, add the edge P → Q and printEdge P -> Q (R). - Repeatedly find a cycle using DFS: start from the processes in alphabetical order, visit neighbours in alphabetical order, and report the first cycle found as
Cycle: P1 -> P2 -> P3 -> P1(starting from the node where the back edge points). Abort the process of the cycle with the smallest cost (ties: alphabetical) — printAbort P2 (cost 10)— and remove it with all its edges. - When no cycle remains, print
No deadlockif there was never a cycle, otherwiseDeadlock resolved.