https://www.geeksforgeeks.org/detect-cycle-undirected-graph/
Note that we only need one dict! This is easier than Detect Cycle in a directed Graph, where we need 2 dicts.
Note that if the input graph may be disconnected, we just need to try starting from all nodes.
ref: https://www.geeksforgeeks.org/detect-cycle-in-a-graph/.
Note that we need 2 dicts!
Note that if the input graph may be disconnected, we just need to try starting from all nodes.
Exercise: