Find an undirected cycle
Check whether the map has a loop of roads. A loop lets you leave a town and return home without retracing a road.
Remember the parent of each vertex. An edge to an earlier ancestor, other than the parent edge, closes a cycle.
With adjacency lists, traversal takes O(V + E) time for V vertices and E edges.