I'm trying to solve this graph problem.
My idea so far is:
1.Build dfs tree.
2.Direct every span edge upwards.
3.Direct every back-edge downwards.
4.Traverse tree from the bottom (i.e. maximum level vertices).
5.Do the operation 2(instruction no. 2) described in the problem.
6.Flip the back-edges for the vertices which are at the current level(L).Move to the next level(i.e L-1)
7.Stop when we reach the root.
But This approach is using more than 700 moves of the 2nd type, which exceeds the limit.
Does anyone have a better approach?