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->V] =1;if(!c[p->v] | | DFS (C[P->V)) {C[u] = p->v; C[P->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)