EC_P - Critical Edges : Getting TLE in Java

I was practising this problem on spoj: EC_P - Critical Edges. I am having hard time in optimising to get AC. I tried fast I/O as well. But still getting TLE. Can any one help me with this on how can we optimise it in java ?