[algorithms][is_valid] re-design the complement graph: store neighbors
in the graph instead of at each vertex; store DFS data for detecting
cycles outside the vertices;