Reglious People Graph 3 test case is giving wrong ans


Please correct my code why it is failing for 3 test case

Instead of finding total no of components initially. Do dfs from each node and find size of each component. Then you just have to multiply noOfcomponents * templecost + roadcost*(sizeofeachcomponent-1)

why to use dfs …when we can compute from number of component

Please provide me the sample input for which my test case is failing

please tell why not my not approach is correct …give me the test case for which it is failing

brooo i checked all the corner cases
but could not see any wrong answer

i am providing a code done with similar approach


Made the changes but now only 2 test case is passing


now only two cases are passing

this is even worst ealier only 3 test case were not passing

please revisit the code i have send
and try to recode from start

@Ram_Vilash_Kumar
One such testcase where your code fails :
Input :
1
62 39 97 56
59 30
48 2
5 22
48 59
11 15
18 37
14 21
39 2
31 13
49 32
3 13
61 5
38 53
33 24
18 32
44 36
42 25
7 33
39 57
59 52
21 58
47 16
15 14
18 9
35 27
49 17
22 42
50 48
42 39
7 2
21 9
11 52
46 42
15 49
26 24
24 57
28 2
26 32
60 29

Your Output :
4743

Expected Output :
4538

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.