codeLink : https://ide.codingblocks.com/s/197625
above is my code link and I have commented my approach please correct my code and specify my error(in a nutshell I wish to group connected vertices by storing their same pparent in parent array than counting how many shells have common parent and accordingly calculating them u)
Religious people wrong output
Hello @Divya_321,
There are the following problems in your code:
-
An isolated node in the graph:
Example:
1
4 2 2 1
1 3
3 2
Expected Output:
6 (two temples and two road, 4 is iolated)
Your Output is:
4 -
1
3 2 5 1
1 3
3 2
Expected output:
7 i.e two roads and one temple.
Your Output:
10 i.e. 2 temples. -
When there are two different set of roads:
Example:
1
4 2 2 1
1 3
4 2
Expected Output:
6 (2 temples and 2 roads)
Approach:
-
if a<=b, then create a temple in each city.
and print a*n. -
Now create a array/list or map for visited nodes of size v+1
-
Loop for each node: i=1 to v //To keep track of isolated nodes also.
taking i as source node,
do BFS if visited[i]==false -
during BFS:
make a tample at source node and
build a rode for each city where we can reach from the source and mark these nodes as visited.
Hope, this would help.
Give a like if you are satisfied.
Sure I will try your approach, , ,
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.
@S18ML0016 I have modified my code as per your guideLines but than also I am able to pass only two test cases , please correct my code and specify my errors 
codeLink : https://ide.codingblocks.com/s/202469
Hello @S18ML0016,
There are total “city” number of cities given in the input.
As you have defined a map for adjacency list and iterating for the the nodes present in adjacency list.
It will pass the test cases for isolated nodes.
Reason:
There is no road to that node.
So, adjacency list will not have any data for this node.
Hence, you will skip this node will iterating inside the findcost() function.
Hope, this would help.
Give a like if you are satisfied.