Ahmad_Elsagheer's blog

By Ahmad_Elsagheer, 8 years ago, In English

Hello,

I have tried to solve this problem [Promotions]. It was in SWERC 2015. This problem is reduced to counting successors of every node in a DAG. My best algorithm to solve it is to make a dfs for every node and count the number of reachable nodes. So, the complexity is O(VE), but I got TLE with Java. I checked online solutions and found nothing different (except they are in C++). I wonder if there is a more efficient algorithm, maybe O(V^2) or if someone can provide an efficient AC Java implementation for it.

Thanks!

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

»
8 years ago, # |
  Vote: I like it +16 Vote: I do not like it

There is no known algorithm with complexity better than O(VE/32). That one is achieved using bitsets.

In RAM model it is actually O(VE/log(V+E)).

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    That's interesting. Thanks!

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it +14 Vote: I do not like it

      Note that with 64-bit integers used as bitsets, you have V / 64 instead and under the given constraints, that's something like O(80E) per test case. Bitsets are a very useful thing.