There are also implementations of Hungarian algorithm that do not use graph theory.
Rather, they just operate with cost matrix, making different transformation of it (see  for clear explanation).
In this article we’ll deal with one optimization problem, which can be informally defined as: Assume that we have N workers and N jobs that should be done. Let’s look at the job and workers as if they were a bipartite graph, where each edge between the .
For each pair (worker, job) we know salary that should be paid to worker for him to perform the job. Then our task is to find minimum-weight matching in the graph (the matching will consists of N edges, because our bipartite graph is complete).
(For example, (W4, J4, W3, J3, W2, J2) and (W4, J1, W1) are alternating paths)If the first and last vertices in alternating path are exposed, it is called (because we can increment the size of the matching by inverting edges along this path, therefore matching unmatched edges and vice versa). And now let’s illustrate these steps by considering an example and writing some code.
((W4, J4, W3, J3, W2, J2) – augmenting alternating path)A tree which has a root in some exposed vertex, and a property that every path starting in the root is alternating, is called an . Find(1)and replace existing labeling with the next one:(2)Now replace with Step 3. As an example we’ll use the previous one, but first let’s transform it to the maximum-weighted matching problem, using the second method from the two described above.In order to avoid this, on each step we can just modify the matching from the previous step, which only takes O(n2) operations.It’s easy to see that no more than n2 iterations will occur, because every time at least one edge becomes 0-weight. This is simply a function (for each vertex we assign some number called a label).Let’s call this labeling feasible if it satisfies the following condition: .In other words, the sum of the labels of the vertices on both sides of a given edge are greater than or equal to the weight of that edge.In other words, it only includes those edges from the bipartite matching which allow the vertices to be perfectly feasible.Now we’re ready for the theorem which provides the connection between equality subgraphs and maximum-weighted matching: is called alternating if its edges alternate between M and E\M.Then, after the contest, you find out in the editorial that this problem can be simply reduced to a classical one.If yes, then this tutorial will surely be useful for you. We can also rephrase this problem in terms of graph theory.We’ll handle the assignment problem with the Hungarian algorithm (or Kuhn-Munkres algorithm).I’ll illustrate two different implementations of this algorithm, both graph theoretic, one easy and fast to implement with O(n4) complexity, and the other one with O(n3) complexity, but harder to implement.