|
Well, it's connectivity!
1. If you want to know if any two people can reach O (1) time, I only think of O (n ^ 3) algorithm. Passing closures can be, Freud can also, just a little Change it!
2. Of course, if you don't need to judge in O (1) time, you can divide the graph into several connected sets. This can consider the spanning tree method (the minimum spanning tree is not necessary), and dfs can also, depending on the situation The complexity of this creation is low
If the graph does not change much, it is mainly for query, or use 1, otherwise use 2
I can only think of these, expecting more efficient algorithms |
|