Study and organize the Bipartite Graph

Source: Internet
Author: User

Study and organize the Bipartite Graph

I learned about the bipartite graph today and summarized it as follows:

There are many problems with the bipartite graph, but the final result is to find the maximum number of matching.

Maximum matching of bipartite graphs and common graph creation methods

Point 1:

Minimum vertex overwrite in a bipartite graph = maximum number of matches

Minimum vertex coverage: that is, the minimum vertex is used to cover all edges.


Point 2:

Minimum path overwrite = number of vertices-Maximum number of matching in a Bipartite Graph

Minimum path overwrite: this parameter is also called "least side overwrite". It means to overwrite all vertices in the graph with a minimum number of non-intersecting paths.


Point 3:

Maximum Independent Set of a bipartite graph = number of vertices-Maximum number of matching

Independent Set: A Point Set independent of all connected edge sets, that is, a point set that is not connected to any point in the graph.


PS: there is no way to learn graph theory well. You can click questions, click questions, or click questions again.


Pku 1466 Girls and Boys http://poj.org/problem? Id = 1466


This is a typical binary matching question, and it is very simple. You can use the template to AC.

Select m points in graph G of N points so that there is no edge between them. Calculate the maximum value of m.
If graph G meets the condition of bipartite graph, you can use Bipartite Graph Matching. the maximum number of independent set points = N-the maximum number of matching.


Maximum number of independent nodes = unmatched nodes + number of matched nodes/2 (1) (set n = number of matched nodes/2) can be understood as removing the matching n nodes on a side of the Bipartite Graph,

N nodes corresponding to the other side are not matched)


Unmatched node = number of vertices-Number of matching (2)


Obtained from (1) (2): Maximum Independent Number = number of vertices-half of the matching number


Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010920914230/


2: pku 1719 Shooting Contest Bipartite Graph Matching
Http://blog.163.com/zjut_nizhenyang/blog/static/169570029201010199320592/
Create a graph and match the output.


// Question analysis: the question actually requires you to take the x and y coordinates as the two node parts of the bipartite graph, and then let you find a match, then, the corresponding node is output according to the node sequence of one part.
// Train of Thought Analysis: directly use the Hungary algorithm implemented by dfs to solve the Bipartite Graph
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/169570029201010199320592/




3: pku 1422 Bipartite Graph with minimum path coverage
Http://poj.org/problem? Id = 1422
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/16957002920101025922340/




4: pku 2594 Treasure repair ation floyd re-create a graph + minimum path overwrite + Bipartite Graph
Http://poj.org/problem? Id = 2594
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010102583552414/




5: pku 3216 Repairing Company floyd Shortest Path + maximum matching of Bipartite Graph
Http://poj.org/problem? Id = 3216
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/169570029201010257563738/




6: pku 1904 King's Quest strongly connected branch, Bipartite Graph
Http://poj.org/problem? Id = 1904
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010102572022595/




7: pku 3041 bipartite graph minimum vertex overwrite = maximum number of matches
Http://poj.org/problem? Id = 3041
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010102462244415/




8: zjut 1321 Dividing Bipartite Graph Matching
Http://acm.zjut.edu.cn/ShowProblem.aspx? ShowID = 1321
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010102454153206/




9: pku 2771 Guardian of Decency bipartite graph, Maximum Independent Set
Http://poj.org/problem? Id = 2771
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111065019932/




10: pku 1325 Machine Schedule bipartite graph minimum vertex Overwrite
Http://poj.org/problem? Id = 1325
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111035942586/




11: pku 1486 Sorting Slides required Edges
Http://poj.org/problem? Id = 1486
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111032443864/




12: pku 2536 Gopher II Bipartite Graph Matching
Http://poj.org/problem? Id = 2536
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010117113611862/




13: pku 2239 Selecting Courses Bipartite Graph Matching
Http://poj.org/problem? Id = 2239
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/16957002920101171151319/




14: pku 1274 The Perfect Stall Bipartite Graph Matching
Http://poj.org/problem? Id = 1274
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010117102245344/




15: pku 2724 Purifying Machine bipartite graph minimum path Overwrite
Http://poj.org/problem? Id = 2724
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111495830231/




16: pku 3020 Antenna Placement bipartite graph minimum path Overwrite
Http://poj.org/problem? Id = 3020
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111485846859/




17: Application of pku 2446 bipartite graph maximum matching
Http://poj.org/problem? Id = 2446
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/169570029201011148555347/




18: pku 2226 Muddy Fields bipartite graph minimum vertex Overwrite
Http://poj.org/problem? Id = 2226
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111365944100/




19: zjut 1478: minimum point coverage for saving losses in a Binary Graph
Http://acm.zjut.edu.cn/ShowProblem.aspx? ShowID = 1478
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111365248521/




20: pku 2060 Taxi Cab Scheme bipartite graph minimum path Overwrite
Http://poj.org/problem? Id = 2060
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/16957002920101111433360/




21: pku 1548 Robots bipartite graph minimum path Overwrite
Http://poj.org/problem? Id = 1548
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/169570029201011113748927/




22: pku 3692 Kindergarten: The maximum independent set of the Bipartite Graph.
Http://poj.org/problem? Id = 3692
Reference: http://blog.163.com/zjut_nizhenyang/blog/static/1695700292010111075931537/


Bipartite Graph Matching

G: array [1 .. maxn, 1 .. maxm] of boolean;
Y: array [1 .. maxm] of boolean;
Link: array [1 .. maxm] of longint;
Function find (v: longint): boolean;
Var I: longint;
Begin
For I: = 1 to m do
If g [v, I] and (not y [I]) then
Begin
Y [I]: = true;
If (link [I] = 0) or find (link [I]) then
Begin
Link [I]: = v;
Find: = true;
Exit;
End;
End;
Find: = false;
End;
Begin
// Read the graph into array g [] []
For I: = 1 to n do
Begin
Fillchar (y, sizeof (y), 0 );
If find (I) then inc (ans );
End;
I use C ++. This PASCAL program is from another place.
N and m are the numbers of nodes on both sides of the two graphs respectively. The nodes on both sides are numbered by 1. n, 1. m, respectively.
G [x] [y] = true indicates that x and y are connected by edges.
Link [y] records the x nodes currently connected to the y node.
Y [I] records whether I node in y has been accessed.

The idea of the algorithm is to constantly find the augmented rail and increase the number of matching. The augmented rail, as the name suggests, refers to a path that can increase the number of matching. In the matching problem, the augmented orbit is represented by an "staggered track". That is to say, this path composed of the edges of the graph has not been matched yet, the second side is involved in the matching, and the third side does not .. the last edge is not involved in the matching, and the start point and end point have not been selected. in this case, it is clear that he has an odd number of edges. for such a path, we can change the first edge to matched, and the second edge to unmatched... and so on. that is to say, all edges are reversed. It is easy to find that after this modification, the matching is still valid, but the number of matches is increased by a pair. in addition, an independent edge connecting two unmatched points is obviously also staggered. it can be proved that when the augmented orbit cannot be found, a maximum matching is obtained. this is the idea of the Hungarian algorithm.
In the code, find (I) is to find whether there is an augmented track starting from x point I. If so, the above operation is performed, and the code is recursive, so it does not seem obvious that, try to draw a picture.

P.S. I was dumb. I used to spend a lot of time learning Hungary algorithms to understand the meaning of this Code. I hope the author can understand it quickly, so I described the algorithm in a very poor and nonstandard language. hope to be satisfied

Problem description: write out the maximum matching algorithm for a bipartite graph, in the c ++ language.

This should be your homework. Haha, my personal suggestion: it is best to do it by yourself to learn c and c ++ languages. The time at school is precious, if you want to be a good programmer, you have to lay a good foundation in school so that the work can be guaranteed. This question should be part of your homework. Try to finish it by yourself, after you finish, you will find that you have gained a lot, not only in terms of knowledge, but also in terms of learning pleasure and Methods. As a person, you can share your personal experience with you, I wish you a better learning experience. If you have any difficulties, you can join us.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.