APIO 2011 How to solve Table Coloring Problem using DFS (Two - Coloring)?

Problem Link: https://usaco.guide/silver/dfs#problem-apio-11-TableColoring
Solution: https://usaco.guide/problems/apio-2011table-coloring/solution

As written in solution this problem can be solved either using DFS or DSU. Since I’m learning DFS (Two - Coloring) in USACO Guide so I would like to solve it using DFS Two-coloring.

I’ve tried to implement it but it failed and got WA on most test cases.

I’ve changed the link to the problem to the link from USACO Guide.

Would you help me, please? I really need your help :slightly_smiling_face: