See it before solving to save your time, ques statement and test cases are wrong

  1. Edges in E are bidirectional.
  2. Number of vertices are A+1.

this Test case should give -1 as ans.
6
1 3 1 5 5
2
4
1 3 6 7 4

Click here to start solving coding interview questions