i simply run dfs on all vertices and update both child and parent array but not getting right ans plz have a look on code…
Beautiful vertices?
yeah i think in hint also they do somthing like this
i have made some modifications in your code but then also it is passing only one test case .
i think your logic is incoorect .
okay so tell me the better approch
hey @Ashu1318 i have made your approach some way better and it is right here https://ide.codingblocks.com/s/352710
but as i told you it doesnt pass every test case so the correct code is https://ide.codingblocks.com/s/352711 .
if you have any doubt in understaning please ask here and if your doubt is cleared please mark it as resolved .
Happy Learning !!
dont undestood the logic in dfs function
hey @Ashu1318 please try to dry run for any simple test case .
you will be able to understand the logic .
you cannot understand graphs code without doing the dry run .
okay i go it thanks…
actually i have an problem in quetion of codeforces 510C ,can u tell me how to make graph in such quetions, life if they gave strings how to use topological sorting here??
hello @Ashu1318 yes we can definitely help you but you have to raise doubt again for it after marking this doubt as resolved .