On a 2D plane there is a set of vertices V and segments S. Each segment has 2 vertices, and each vertex knows segments that use it. That creates a kind of a graph.
I would like to find all polygons as is depicted above. A polygon P is a set of n segments.
I tried BFS for each vertex with first cycle detection and duplicates removing. It unfortunately doesn't work for specific cases, for example it won't find P5 on picture below.