Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя anirudhmittal21k12k

Автор anirudhmittal21k12k, история, 16 месяцев назад, По-английски

I am not able to find a blog or video which would describe how to delete an index and all its children while doing problem http://www.usaco.org/index.php?page=viewproblem2&cpid=644 . I really wanted a dsu solution. Here my implementation just have to implement delink function correctly please help. Here my submission link https://ide.usaco.guide/NX__5jD-hKhlahQ_iks

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
16 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

you can use an approach similar to this Finding bridges

»
16 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Let each edge have time when it will be closed. It's easy to see that it will happen when one of the nodes it connects gets closed. Let the time when some edge is removed be t. Before t-th removal, the edge was in the graph and later it was not. So we can go from the back when graph has no edges. We will iterate and add all edges with t=N-1, then t=N-2, then t=N-3 and so on. After each addition, we can check if graph is connected by keeping track of number of connected components.