题目

代码
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int g[N][N], st[N];
int match[N];
int n, m, k;
bool find(int x)
{for(int i = 1; i < m; i++){if(!g[x][i] || st[i]) continue;st[i] = 1;if(!match[i] || find(match[i])){match[i] = x;return true;}}return false;
}
int main()
{while(cin >> n, n){memset(g, 0, sizeof g);memset(match, 0, sizeof match);cin >> m >> k;for(int i = 1; i <= k; i++){int t, a, b;cin >> t >> a >> b;g[a][b] = 1;}int ans = 0;for(int i = 1; i < n; i++){memset(st, 0, sizeof st);if(find(i)) ans++;}cout << ans << endl;}
}