UVa 11080 - Place the Guards

Problem Number - Problem Name

 * [Problem Link]

Summary
Its a simple bipartite graph Problem...like as UVA 10004.

Explanation
If Its not BiGraph print -1;

Solution
http://shawonruet.com/2016/07/uva-11080-place-guards.html

Implementations
Notes/Hints on actual implementation here.

on approach for bicoloring (determine the graph is bipartite or not ) is use BFS method.

see this sample solution for this problem :

and in main method of your code such checking should be use :

Optimizations
Optimizations here.

Input
5 5 1 0 1 5 0 1 0 4 2 0 1 2 3 5 5 0 1 1 2 2 3 0 4 3 4

Output
4 5 1 2 -1