Ok... I was just looking for a problem to BFS and got TLE from this problem. It got ACed using ad hoc with pruning the impossible case... Quite weired and disappointing...