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://codeforces.me/contest/667/problem/D
My solution Link: http://codeforces.me/contest/667/submission/17699475