Religious places problem

though i have passed all the test cases
but from my logic i am not getting right ans for tree ie
for the tet case 5 4 2 1 where edge are 1->2->3->4->5
ans should be 7 i am getting 6

hello @royprincejmp
answer should be 6 only.
we can build a temple on vertex 1 .which will cost 2. and then repair all the roads.
total 4 roads are there so cost will be 4.
total cost will be = 4+2=6