Can you tell for which test case my code is failing.
Please check code for beautiful vertices problem
I did the quetion using dfs and got correct answer but I want to know why this approach is wrong??
ur logic is correct.
the issue is with the constrcution of graph.
u r assuming that if x–y edge is given then x will be the parent of y.
which is wrong.
the parent and child will be decided by the least value of that component.
for example->
3–4--1 (they all are in a single component)
here 1 is least value so 1 is master parent.
and its child will be 4. and 4 child will be 3
so parent- child graph should be like this->
1 --> 4–>3
i get that 1 is master parent as its smallest value of this component. but how is 3 a child of 4??
1 is master parent.
so all its negibhour will be its child (4)
and similary all neigbhours of 4 will be its child ( 3 ).
so on… till u reach leaf
In the hint video of this question, it is given then for graph: 2–3--1
the directed graph becomes: 1–>2–>3
Which I think is wrong. Shouldn’t it be: 1–>3–>2
…
yeah , it should be 1–>3–>2
there is no edge between 1 and 2 so that is not correct
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.