Summary of minimum edge coverage in vernacular-Additional hdu1151 answer report

Source: Internet
Author: User

When I first saw this question, I thought it was very clear, that is, I didn't know how to match it...

I went to the Internet to read a lot of people's problem-solving reports, but for New Contacts"Minimum edge coverage"For me .... it's still very difficult .... as a result, I began to learn the "largest independent set" and "least point coverage" thinking methods again: before learning a seemingly advanced knowledge point, I would like to have a rough understanding of what this is, the concept will be better understood. (I hope this blog will be clear in the future, and I am very honored to be helpful to those who are new to "minimum edge coverage )):

First, the first case of the question is graphical (first, good understanding of graphics, and second, a lot of people get bored when they see the text. Third, how can we squeeze graph without drawing?) we regard the intersection as a point and the street as a side, just like:

We need to select the least paratroopers to land at some intersections so that they can finish all intersections (note that it is a one-way edge). We can easily choose to land at intersection 2, go 3, and then go 4, then we land at the intersection of 1, and the two in total will be able to access all the intersections. We can see that we can regard Street 3 and street 1 as one side, overwrite the intersection of 2.3.4:

In this way, we have a vulgar understanding of "least side coverage ".

The next step is to solve this problem and match it with Hungary: as I first came into contact with binary matching, I wanted to use a street (simplified as a point) to match the intersection: (who knows ...)

I don't know how to match it ....

Next let's take a look at the relationship between the minimum edge coverage and the binary matching: (if you think it is annoying to read the text concept .. you can see the following graphic description, but it is more helpful to understand it by combining text and graphics) (from Baidu encyclopedia)

The relationship between path coverage and bipartite graphs (must be a directed graph without loops ): Minimum path overwrite = | p |-Maximum number of matches (| p | a specified number of points)The method for finding the maximum number of matches is to divide each vertex PI in P into two vertex PI 'and PJ ''. If there is a side of PI to PJ in P, in the bipartite plot P, there is a undirected edge connecting PI 'and PJ ''. Here PI' is the outbound edge of PI in P, PJ ''is an inbound edge of PJ in P. For the formula: Minimum path overwrite = | p |-Maximum number of matches, this can be understood. If the number of matches is zero, therefore, P does not have a directed edge, so it is clear that it has: Minimum path overwrite = | p |-Maximum number of matches = | p |-0 = | p |; that is, the minimum number of path overwrites of p |; the number of path overwrites when the P is not in the matching edge | p |; if a matched edge PI '--> PJ ''is added to P, an edge connecting PJ by PI exists in the path overwrite of P, that is to say, Pi and PJ are in one path, so the number of path overwrites can be reduced. In this way, the matching edge will be added, and the number of path overwrites will be reduced every time one is added; when the matching edge cannot be increased, the number of path overwrites cannot be reduced, and the previous formula is available. However, this only shows that each matching edge corresponds to path overwrites. A directed edge is connected between two vertices in a path. The following shows that the directed edge of each connection between two vertices in a path overwrite corresponds to a matching edge; similar to the above, for each directed edge PI connecting two vertices in the path overwrite ---> PJ, we can create an edge connecting PI 'and PJ ''in the matching graph. Obviously, this graph is a matching graph (this is easily proved by the reverse verification method, if the obtained graph is not a matching graph, the two sides PI '--- PJ ''and PI' ---- PK'' must exist in this graph. (J! = K), there will be two sides in the path overwrite graph --> PJ, PI ---> PK, and there will be more than one path starting from Pi, this is in conflict with the path overwrite diagram. Another situation is that there is pi '--- PJ '', PK' --- PJ'', which is similar to the verifiable situation.) at this point, this shows the one-to-one correspondence between the matching edge and the edge connecting the two vertices in the path overlay diagram. This also shows that the previous formula is true! Let's draw a picture based on the above conceptual method .... let the intersection match with the dot. Then the line in the figure means that there is a road on the first to go to the third, and there is also a road on the second to go to the third, no. 3 has a route to No. 4. As you can imagine, No. 1 and No. 2 can be chosen by an umbrella guard to go to No. 3... (A match), and then from the 3 to the 4, the first 1/2 ----> 3 ------> 4 match to go through three points, there is only one more point left .... So Minimum edge coverage = | p |-maximum matchingThis formula is quite clear:
// 0 Ms 244 K # include <stdio. h> # include <string. h> # define Max 121int no_in, no_st; // Number of intersections, number of streets bool map [Max] [Max]; // map [I] [J] indicates that there is a street at intersection I that can reach the int link [Max] at intersection J; bool useif [Max]; bool DFS (INT T) {for (INT I = 1; I <= no_in; I ++) {If (! Useif [I] & map [T] [I]) {useif [I] = true; if (link [I] =-1 | DFS (link [I]) {link [I] = T; return true ;}} return false ;} int match () {int sum = 0; memset (link,-1, sizeof (Link); For (INT I = 1; I <= no_in; I ++) {memset (useif, false, sizeof (useif); If (DFS (I) sum ++;} return sum ;} int main () {int t; int, b; scanf ("% d", & T); While (t --) {memset (MAP, 0, sizeof (MAP); scanf ("% d ", & no_in, & no_st); For (INT I = 1; I <= no_st; I ++) {scanf ("% d", & A, & B ); map [a] [B] = 1; // note that the single path} printf ("% d \ n", no_in-match ();} return 0 ;}
Personal ignorance... Welcome to correction and discussion

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.