# [ACCEPTED]-Topological Sort with Grouping-graph-theory

Accepted answer

Label all root nodes with a level value 8 0. Label all children with level value parent+1. If, a 7 node is being revisited i.e it already has 6 a level value assigned, check if the previously 5 assigned value is lower than the new one. If 4 so, update it with the higher value and 3 propagate them to the descendents.

now, you 2 have as many groups as there are unique 1 level labels 0 ... K

Source:
stackoverflow.com

More Related questions

Cookie Warning

We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.