Some Speedups for Matching Algorithms
First a very silly trick.
During IAEPC, there was a problem that could be modeled as a bipartite graph with
Somehow maroonrk managed to squeeze TL on that.
His trick was the reverse all edges and compute the cost from sink to source.
The test case creator did not consider that and therefore the tests were weak and he managed to scam.
Now for more legitamate tricks.
Bitset Kuhn’s
We know that for unweighted bipartite matching, it is
But actually there is a way using
Although I have no idea how practical this idea is compared to using DInic’s.
Kuhn Speedup when Flow is small
Note that we only need to actually reset the visited graph from the dfs when we successfully find an augmenting path.
Therefore, the time complexity of Kuhn’s is really
If we know that
Special Case of Weighted Bipartite Matching
Suppose a have a bipartite matching where if we have edges
It turns out we can use Kuhn’s to solve this min-cost max-flow problem. And we actually perform MCMF algorithm when doing so.
The algorithm is to sort the vertices on the left side by
If one models this as a MCMF graph, we can see that this is the strategy that MCMF will take, since the edges with cost are all directly connected to the source.
So we claim that the only viable augmenting paths are those that go through exactly
Suppose otherwise, and there is a viable augmenting path that uses the edges
But we know that
So it is valid to take
So each augmenting path only uses
So the algorithm can be seen as picking the vertex on the left side with the minimum
There is another more ad-hoc way to think about this.
Suppose
We will show inductively that the optimal solution must contain the vertices
Suppose we already know the optimal solution must contain the vertices
Firstly, we must have
Now we will show that we can change one of the
Now, consider the matching
Consider the union
Otherwise, the path ends in one of
Therefore, we have two different but probably very similar ways of proving our claim.
These last two optimizations are used in CF1728F, if you want to solve that.
EDIT: Patrik Pavic told me that you can prove this easily since the sets of valid