1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include<cstdio> #include<cstring> using namespace std; const int maxn=500+10;
struct Max_Match { int n; bool g[maxn][maxn]; bool vis[maxn]; int left[maxn];
void init(int n) { this->n=n; memset(g,0,sizeof(g)); memset(left,-1,sizeof(left)); }
bool match(int u) { for(int v=1;v<=n;v++)if(g[u][v] && !vis[v]) { vis[v]=true; if(left[v]==-1 || match(left[v])) { left[v]=u; return true; } } return false; }
int solve() { int ans=0; for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(match(i)) ans++; } return ans; } }MM;
int main() { int n,k; scanf("%d%d",&n,&k); MM.init(n); while(k--) { int u,v; scanf("%d%d",&u,&v); MM.g[u][v]=true; } printf("%d\n",MM.solve()); return 0; }
|