I tried to solve the problem last 3 days . I didn't understand where my algorithm not work ! I use strongly connected component and dynamic programming . Please provide some suggestion that how can I solve the problem . Thanks in advance .
Problem link : http://www.spoj.com/problems/BREAK/
My solution link : http://ideone.com/5WMx0q
Solved !