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
| #include <bits/stdc++.h> #define LL long long #define Pi acos(-1.0) #define INF 2147483646 #define eps 1e-9 #define MS 509 #define mss 17 using namespace std;
LL n,m,k; LL mp[MS][MS]; LL vis[MS]; LL match[MS];
int find(LL x){ for(int i=1;i<=m;i++){ if(mp[x][i] && !vis[i]){ vis[i] = 1; if(!match[i] || find(match[i])){ match[i] = x; return 1; } } } return 0; }
int main() { ios::sync_with_stdio(false); while(cin >> k){ if(k == 0) return 0; memset(match,0,sizeof match); memset(mp,0,sizeof mp); cin >> n >> m; LL u,v,ans=0; for(int i=1;i<=k;i++){ cin >> u >> v; mp[u][v] = 1; } for(int i=1;i<=n;i++){ memset(vis,0,sizeof vis); if(find(i)) ans++; } cout << ans << endl; } return 0; }
|