HDU 1151 Air Raid (minimum path overlay)

Source: Internet
Author: User

Transmission Door

The main topic: There are n intersection M road. Give you the starting and ending points of each road, so you can find a minimum number of soldiers (each soldier can only walk along one road and not be associated with other soldiers ' routes) to finish the whole picture.

Because this is a bare topic with the smallest path covered, I'll write my own understanding.

To do the minimum path coverage, first to split the point, each point is split into two, a representation, a representation in. Then make the maximum match, because each vertex of the binary graph can have only one matching edge, so the path is not crossed.

For conclusion: Minimum path coverage = number of vertices-the maximum number of matches after a split. This is because two points on one path in the match are two points after the split, which is equivalent to two 1/2 points in the original image. So the total number of vertices-the maximum number of matches is equal to the minimum path coverage.

#include <cstdio>#include <cstring>#define MAXN#define MAXM 30000struct node{intV Node*next;} Edge[maxm * *],*adj[MAXN * *],*mcnt= Edge;void Addedge (intUintV) {Node*t= ++mcnt;    T->v = v; T->Next= Adj[u]; Adj[u] = t;}intNm, C[MAXN * *], Cnt;bool Vis[maxm];bool DFS (intu) {Vis[u] =1; for(node*p= Adj[u]; P p = p->Next)    {if(Vis[p->v])Continue; VIS[P-&GT;V] =1;if(!c[p->v] | | DFS (C[P-&GT;V))            {C[u] = p->v; C[P-&GT;V] = u;return 1; }    }return 0;}intMain () {intT scanf"%d", &t); while(T-)        {mcnt = Edge; memset (ADJ,0, sizeof ADJ);intA, B; CNT =0; scanf"%d%d", &n, &m); for(inti =1; I <=m; i + +) {scanf ("%d%d", &a, &b);        Addedge (A, B + N); } memset (C,0, sizeof c);intAns =0; for(inti =1; I <= N; i + +)if(!c[i]) {memset (Vis,0, sizeof Vis);            Ans + = DFS (i); }printf("%d\ n", N-ans); }return 0;}

Copyright NOTICE: Please feel free to reprint O (∩_∩) o

HDU 1151 Air Raid (minimum path overlay)

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.