SNGRAPH - Editorial

Can some please explain me how to solve this question using dfs

I used DFS and i got tle

@senbihan , even I did the same thing. It shows wrong answer. Can anyone tell why??

my submission : https://www.codechef.com/viewsolution/13972080

@kaiser123 my code gives correct answer ,i.e 0,0,6,6,6,6,6

As soon as a component gets completely separated , I decrease the total count by 1

Can someone please explain why is N= 1e5 + 5 in the solution provided in the editorial?

Someone please explain the functions in code given in editorial.I have just studied the concept of DSU and its working.Looking for implementation.