I am getting Time Limit Exceeded for that problem. If anyone can please help. Thanks in advance :)
My approach: By calling N times BFS i got all pairs shortest path. Then by recursively i took all possible 4 nodes as there is no sub-problems so only backtracking can handle this.
Problem Link: http://mirror.codeforces.com/contest/667/problem/D
My solution Link: http://mirror.codeforces.com/contest/667/submission/17699475