How can i build different component?

how can i build different component from given edges??

Let u be a vertex and v be its child. Then, check if children[v]>children[u].This way, check for each vertex while traversing the graph in DFS. One important thing to note that actually there are many trees in the input(a graph with no cycles and self loops is a tree). That means , you have to apply DFS for each of these trees.

but how can i decide master parent then enter in arraylist??

go through this code once to understand:

there is no need to decide which is master parent??
and can i solve it without using node class(given in above code)??

yes and you could define a class graph instead with the needed functions

i mean can i solve without these features , any another way to solve it, i don’t want to know can i replace the name node to graph or not.

i dont mean the name changing bro. i mean define a class graph
something along these lines

1 Like