darkahmed's blog

By darkahmed, history, 35 hours ago, In English

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 code (without my template)

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 :)

  • Vote: I like it
  • +11
  • Vote: I do not like it

»
35 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by darkahmed (previous revision, new revision, compare).

»
35 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by darkahmed (previous revision, new revision, compare).

»
35 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Gamed

»
34 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Great

»
34 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Amazing!