DFS on segments

Правка en3, от yoshi_avx, 2026-08-19 08:42:30

Given a directed graph G that consists of (multiple of) a node connected to a segment of nodes, how would you find its SCC?

You may think of...

But here I propose a very simple algorithm that can solve this problem in the same time complexity ($$$O((M + N) \log N))$$$ (with M being the number of segments and N being the number of nodes).

the algorithm

Why this works: dfs or dfs_T will always call on an existing node, so it'll be called n times. The time complexity is obvious from the set complexity.

Application: https://atcoder.jp/contests/arc069/submissions/78513905.

But what about the graph consisting of segments connected to segments? It probably can be solved in $$$O((M+N)\log^2(N))$$$ with the segment tree method, but doesn't apply here. I guess...

Also the problem above has a trivial transpose ($$$|M^T|=|M|$$$) of the graph. This probably makes it easier...

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский yoshi_avx 2026-08-19 08:42:30 111 Tiny change: '$|M^T|=|M|) of the g' -> '$|M^T|=|M|$) of the g'
en2 Английский yoshi_avx 2026-08-19 08:36:33 3
en1 Английский yoshi_avx 2026-08-19 08:35:07 1493 Initial revision (published)