I am trying to solve this problem but unable to do it fast.
In short - we have a graph (directed) and we want to find out from which node (a set of nodes to select from is given) we can visit the most nodes. A straightforward implementation will be to run DFS/BFS from every node and see how many we can visit. But that it too slow as there are over 5000 nodes in the graph. Running 5000 BFS/DFS will be take very long time.
On the other hand I also get a feeling that this problem may have something to do with Disjoint Set data structure? But I am unable to formulate it that way as in my disjoint set implementation some of the mentioned rules.
Can someone give a hint as to how to approach this problem?