Fix for B (f^$#, I could have been in round 2)

If I wasn't lazy and used DFS as I had originally thought, I would
have solved the problem correctly and would have been in round 2.
But I had to come up with some "special" solution for this "simpler"
case. But this case is not "simpler", it is typical case for DFS
(or toposort). Well, till the next year :-)