Verify daisy chain rig

Write codeEasy16 min

Your task

A lighting crew cables a stage rig fixture by fixture, and the rig is signed off only when every fixture sits on one unbroken daisy chain. Fixtures are numbered 0 upward, and links[i] lists every fixture cabled directly to fixture i. A cable shows up in both of the lists it joins, and a list may repeat a cable, which still counts as that one cable. Return true when the rig forms exactly one chain: no fixture carries more than two cables, exactly two fixtures carry a single cable and sit at the ends, and every fixture is reachable from every other by walking cables. A rig holding one fixture and no cable counts as a chain. A fixture cabled to itself is a wiring fault, so return false, and an empty rig returns false as well.

Examples

forms_one_daisy_chain(links: list[list[int]]) -> bool
Example 1
Inputforms_one_daisy_chain([[1], [0, 2], [1]])
OutputTrue
Example 2
Inputforms_one_daisy_chain([[1, 2], [0, 2], [0, 1]])
OutputFalse
Example 3
Inputforms_one_daisy_chain([[1, 2, 3], [0], [0], [0]])
OutputFalse