hasCycles method
Checks if the graph contains any cycles.
Uses depth-first search to detect back edges which indicate cycles.
Returns true if one or more cycles exist in the graph.
Implementation
bool hasCycles() {
return getCycles().isNotEmpty;
}