This is a question asked in hack with infi round 2 ,can any one help how to solve it ?


for the given input

one of the possible path which gives us the answer is 1->3->4->7->3->5->2->1
the answer would be 6 because the distinct vertices are 6 (1,3,4,7,2,5).
as mentioned we can traverse an edge in the opposite direction up to one time, so we are using this opportunity to traverse from 5 to 2.