SRM597 - 500 Div2

Working solution (it passes 4/5 tests) but too complex. It fails
one test due to complexity. Breadth First Search implementation
SRM597 - 500 Div2

Correct solution O(N^2)