yoshi_avx's blog

By yoshi_avx, history, 2 months ago, In English

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...

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

»
2 months ago, hide # |
← Rev. 3  
Vote: I like it 0 Vote: I do not like it

why $$$O((M+N) log^2(N))$$$?

Perhaps creating "Virtual points" could solve this problem in $$$O((M+N) log N)$$$.(use segment tree)

  • »
    »
    2 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    The time complexity comes from the fact that you probably need to connect all pairs of segment tree vertices together. I haven't thought much of this problem, since it's a generalization of the above problem and can solve the transpose case by itself.

    • »
      »
      »
      2 months ago, hide # ^ |
      ← Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      The points on the segment tree are connected to a new point, and the new point is connected to points on another segment tree.

      • »
        »
        »
        »
        2 months ago, hide # ^ |
        ← Rev. 2  
        Vote: I like it 0 Vote: I do not like it

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

        In fact,It can $$$O((N+M)\alpha(N))$$$.Use Kosaraju and DSU.

        • »
          »
          »
          »
          »
          2 months ago, hide # ^ |
          ← Rev. 3  
          Vote: I like it +1 Vote: I do not like it

          isn't that exactly the same as my algorithm but substituting set for DSU?... I guess my algorithm is trivial...

          also, how would you implement the DSU?

          • »
            »
            »
            »
            »
            »
            2 months ago, hide # ^ |
            ← Rev. 7  
            Vote: I like it 0 Vote: I do not like it

            During the two DFS operations of Kosaraju, a union-find data structure was used to maintain the first unvisited point within each interval.

            If a point is visited, it is merged with the next one, and the maximum point within each set is recorded.

            It took me a long time to study the code of a certain player before I understood it.

»
93 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

A problem that seemingly has a nontrivial transpose: https://oj.vnoi.info/problem/icpc26_mn_i.

(I tried to construct the transpose graph but failed).

Hint