I just solved the V-Subtree problem on AtCoder DP Contest, and after solving it, I couldn't find anyone who solved it iteratively, so I decided to share my code with you :)
My idea was that, to do a topological sort iteratively, I thought I had to use Kahn's algorithm. When I found that I was getting a wrong answer, I tried to find the problem, and it turned out that the tree was undirected. After some deep thinking, I realized that I could treat the tree as directed, so I sorted the elements by their distance from the root (any root can be taken since it's undirected). Then, I went on to write the answer code :)
Auto comment: topic has been updated by darkahmed (previous revision, new revision, compare).
Auto comment: topic has been updated by darkahmed (previous revision, new revision, compare).
Gamed
Great
Amazing!