I was trying to solve this problem : http://codeforces.com/problemset/problem/1037/D (Valid BFS) . My submission is :http://codeforces.com/contest/1037/submission/45684523
My method : I am storing parent of each node (using bfs) . then , I am checking that is the new bfs following the order policy , using a queue . The code is neat and small . Please someone help me , I want to know where my algorithm is wrong .