Approach for Fill The Matrix

I was trying out the question Fill the matrix . I thought of using graph coloring for this problem , this is first i used disjoint sets to get all the nodes corresponding to “0” condition and then i used graph coloring for the nodes with value 1 , so that i can find the contradictions .
For my solution i referred this video.
I am not able to prove why this solution will give the right answer .
Please suggest some proof for the method and some other approach as well .

Problem based on a similar idea for anyone interested : Problem Link

1 Like