Pls tell whether am i wrong or right


here is my code , it is giving segmentation fault pls do tell the error .
pls do tell whether my logic is correct or not ???
my logic is i have counted all the componenets in this graph .
if cost of temple is less than cost of road , so my ans would be no. of vertex * cost of temple

other wise
my ans would no. of components * cost of temple + element in each component * cost of road

You got segmentation fault because you make size of array of list = v
but actually it should be v+1 because nodes are from 1 to n so
array size should be v+1

approach is correct but not implemented in correct way
this is correct implementation of this approach