Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

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

Автор CreativeAss, история, 6 лет назад, По-английски

How to handle parallel edges while finding bridges?

I know one way that count occurrence of each edge. After taking input if occurrence of an edge is greater than 1 don't consider it. (As it will never be a bridge).

I wanted to know some other way.

Thank you very much in advance :) Happy Coding

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

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

I'm pretty sure that you actually don't handle this case in a special way. The normal algorithm (DFS) will move back to the parent if there is a parallel edge, and therefore will determine that these edges cannot be bridges.

But obviously something like if (next == p) continue; in the DFS will not longer work. You can fix this by enumerating the edges and check if you if the next edge is equal to the edge that you came from.

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

I have met a problem that involves multiple edges while using tarjan's algorithm to find bridges within some graph. (156D - Clues).

I remember that I have assigned a flag to each edge to indicate whether it has been used or not. In the original tarjan's algorithm, if the next node has been visited, we should implement updating as long as this "next" node is not the "parent" node. Thus, when multiple edges are involved, even if the "next" node has been visited and is just the "parent" node, we should still implement updating if this edge has not been used. The reason is that we move from parent node to the current node with edge e1, but move back to parent node (just the "next" node) with edge e2 (multiple edges), and thus we implement updating to indicate that e1 is not a bridge.