Cant figure out why code is giving runtime error

Hello @aryanv,

You have to create the adjacency list of size V+1.
Reason:
Node can have the value V also.
Modification:
adjList = new list[V+1];

Hope, this would help.

@S18ML0016 its working but giving me wrong answer , can you tell me whats wrong with the logic?

Hello @aryanv,

I have modified your code for the test case given in the question:

Now, your task is to correct it for the following cases:

  1. 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)

  2. 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)

Hope, this would help.
Give a like if you are satisfied.

1 Like