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
| #include <iostream> #include <cstring> using namespace std; const int N = 510; int mp[N][N]; int st[N]; int a[N], b[N]; int n,m; int ans;
bool sp(int v){ for(int i=1;i<=m;i++){ if(mp[v][i] && !st[i]){ st[i] = 1; if(b[i]==-1 || sp(b[i])){ b[i] = v; a[v] = i; return true; } } } return false; }
void solve(){ ans = 0; memset(a, -1, sizeof a); memset(b, -1, sizeof b); for(int i=1;i<=n;i++){ if(a[i]==-1){ memset(st, 0, sizeof st); if(sp(i)) ans ++; } } } int main(){ int k; while(scanf("%d", &k) && k){ scanf("%d%d", &n, &m); int a, b; memset(mp, 0, sizeof mp); while(k--){ scanf("%d%d", &a, &b); mp[a][b] = 1; } solve(); printf("%d\n", ans); } return 0; }
|