You have learned bipartite graphs:
A bipartite graph can be split into two groups with all edges between groups.
Equivalently, you can -color it with no adjacent same-colored nodes.
A graph is bipartite if and only if it has no odd cycles.
Detection uses BFS or DFS with alternating colors. Same-color neighbors mean not bipartite.
The pattern appears in many problems: "split into two groups where X" often means bipartite.
You solved three problems with the same core algorithm. Now go practice more in the problemset.