AcWing 376. 机器任务
原题链接
简单
作者:
Anoxia_3
,
2020-08-14 15:29:26
,
所有人可见
,
阅读 829
#include <iostream>
#include <cstring>
using namespace std;
const int N = 110;
int n , m , k;
bool g[N][N];
int match[N];
bool st[N];
bool find(int x)
{
for(int i = 1 ; i < m ; i++)
if(!st[i] && g[x][i])
{
st[i] = true;
if(match[i] == 0 || find(match[i]))
{
match[i] = x;
return true;
}
}
return false;
}
int main()
{
while(cin >> n , n)
{
cin >> m >> k;
memset(g , 0 , sizeof g);
memset(match , 0 , sizeof match);
while(k--)
{
int t , a , b;
cin >> t >> a >> b;
if(!a || !b) continue;
g[a][b] = true;
}
int res = 0;
for(int i = 1 ; i < n ; i++)
{
memset(st , 0 , sizeof st);
if(find(i)) res++;
}
cout << res << endl;
}
return 0;
}