My test cases are failing- please let me know where I’m mistaken
Religious People- Java
can you explain in brief what logic you have implemented to solve this question?
I have introduced a boolean variable named mandir_banega at each vertex, which will signify if a temple has been created at that particular vertex.
I have written the following methods:
max_Connected_Vertex- this will find the maximally-connected vertex in the graph.
allconnectedpaths- this will find out all the different portions of the graph that are disconnected from each other. And in this method, i have created a temple at the maximally connected node.
bfs- this will find the nearest temple for a particular node.
mandir- this will return the cost of accessing a temple. If the cost of reaching the nearest temple is greater than the cost of creating a new one, then a new temple will be created at that particular vertex.
Lastly, the customsolution method is for taking user input and returning the output
your code is giving null pointer exception when you try to access max of an isolated node.
Try to run your code for :
1
4 2 5 8
1 2
2 3
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.