OJ-Problems-Source/HDOJ/1150_autoAC.cpp

38 lines
905 B
C++
Raw Normal View History

2016-08-13 10:51:15 +08:00
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define M 1005
int map[M][M], vis[M], yy[105], x, y, n, cnt;
int getOne(int i){
for(int j=0; j<y; j++){
if(!vis[j] && map[i][j]){
vis[j] = 1;
if(!yy[j] || getOne(yy[j])){
yy[j] = i;
return 1;
}
}
}
return 0;
}
int main(){
int i, j, a, b, job;
while(scanf("%d", &x)!=EOF && x){
scanf("%d %d", &y, &n);
cnt = 0;
memset(map, 0, sizeof(map));
memset(yy, 0, sizeof(yy));
for(i=0; i<n; i++){
scanf("%d %d %d", &job, &a, &b);
if(a&&b)map[a][b] = 1;
}
for(i=0; i<x; i++){
memset(vis, 0, sizeof(vis));
if(getOne(i))cnt++;
}
printf("%d\n", cnt);
}
}