Daily Spit groove: hahaha haha ha ha ha ha ha haha today is the only time so long since the only big cool (? ) of the day. I, Zhao wit small dodger son with 10 minutes ac the xxx template! Applause and encouragement!
The idea still see XXX blog 70175814 anyway little Dodger son just to stick code
Examples
Rokua P3386 "template" binary map matching
Topic background
Two-part diagram
Title Description
Given a binary graph, the number of nodes is n,m, the number of edges is e, and the maximum matching number of two graphs is obtained.
Input/output format
Input format:
First line, N,m,e
Second to e+1 lines, two positive integer u,v per line, indicating that U,v has a connecting edge
Output format:
Total row, binary graph max match
Input/Output sample
Input Sample # #:
1 1 11 1
Sample # # of output:
1
Description
N, M is less than or equal to 1000,u and V are positive integers less than n and M respectively.
v>m case. Please put v>m< Span class= "Strut bottom" > the data consciously filtered out.
Code
#include <cstdio>#include<iostream>#include<cstring>using namespacestd;intN, M, p, tot =0, ans =0;inta[1001], b[1001], t[1001][1001], vis[1001];intDfsintu) { for(intv =1; V <= m; v++) if(T[u][v] &&!Vis[v]) {Vis[v]=1; if(!b[v] | |DFS (B[v])) {A[u]=v; B[V]=u; return 1; } } return 0;}voidMaxmatch () { for(inti =1; I <= N; i++) if(!A[i]) {memset (Vis,0,sizeofvis); Ans+=DFS (i); } printf ("%d\n", ans);}intMain () {memset (A,0,sizeofa); memset (b,0,sizeofb); memset (T,0,sizeoft); scanf ("%d%d%d", &n, &m, &p); for(inti =1; I <= p; i++) { intx, y; scanf ("%d%d", &x, &y); if(X > N | | y > m)Continue; Tot++; T[x][y]=1; } maxmatch (); return 0;}
Binary graph matching--Hungarian algorithm