5 5 10 0 1 1 1 1 2 2 1 3 3 1 4 4 2 1 5 2 2 6 2 3 7 2 4 8 3 3 9 4 3 0
3
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 110; 18 int mp[maxn][maxn],from[maxn],ans,n,m,k; 19 bool vis[maxn]; 20 bool dfs(int u){ 21 for(int i = 0; i < m; i++){ 22 if(mp[u][i] && !vis[i]){ 23 vis[i] = true; 24 if(from[i] == -1 || dfs(from[i])){ 25 from[i] = u; 26 return true; 27 } 28 } 29 } 30 return false; 31 } 32 int main() { 33 int i,u,v,ans; 34 while(scanf("%d",&n),n){ 35 scanf("%d %d",&m,&k); 36 memset(mp,0,sizeof(mp)); 37 memset(from,-1,sizeof(from)); 38 while(k--){ 39 scanf("%d %d %d",&i,&u,&v); 40 if(u && v) mp[u][v] = 1; 41 } 42 for(ans = i = 0; i < n; i++){ 43 memset(vis,false,sizeof(vis)); 44 if(dfs(i)) ans++; 45 } 46 printf("%d\n",ans); 47 } 48 return 0; 49 }