I made this solution using DSU to find the number of components and the minimum number of edges in the components, all the test cases are passed, in test case 4, as i checked, segmentation fault is happening i dont know why, my guess is because the array length of parent[] and ranks[] is too much in test case 4. Please solve this
Test case 4 run error (Religious people)
in the input u r given 1 based indexing, but ur code logic is based on 0 based indexing.
also u need to build remaining roads of every components so u need to add that cost as well
correct it and then try
ohhh yeah, my bad… it worked now… thanks
corrected code: https://ide.codingblocks.com/s/445415
is there any other way to approach this a problem without using DSU?
yeah . . . . run dfs from every unvisited node to get size of component and then add cost of this component in ur answer and move to next unvisited node
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.