Beautiful vertices

wrong answer

Hello @gulati.anmol10

Your have implemented the new12 function incorrectly
Here is the modified code

Your program produced wrong output on the below test case.
5 3
2 1
3 1
3 4

Test cases will NOT still pass because the question is NOT explained properly in the problem statement.
The edges that are provided in the question are NOT the final edges.
Example:-
7 5
2 1
3 1
4 3
6 5
6 7

Here in this input we can see that there are 2 connected components.
In the first connected component {1, 2, 3}, 1 is the master vertex (“In any connected component of the graph, vertex with the lowest value in that component serves as the master parent” given in the question) so there are NO incoming edges on vertex 1 but only outgoing edges.
So edge 2 1 is like 1->2, edge 3 1 is like 1->3, and egde 4 3 is like 3->4

Similarly in the second component {5, 6, 7}, 5 is the master vertex and edge 6 5 is assigned direction 5->6 and edge 6 7 is 6->7.

Modify your code to assign directions to the edges as above and then solve the problem.

The correct code


In the above code
To find the directions assigned to each edge, we start from the master vertex and for each connective edge i
we push realList[MasterVertex].push_back(i) to the real list, then we do the same for their children.
I have used the set to find the master vertex of each component.

If you still need any help, leave a reply and I will help you out.

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.

how is this possible for 6 5 it is 5->6 and for 6 7 it is 6-> 7 ??? why ??