AcWing 376. 机器任务
原题链接
简单
作者:
最后五分钟
,
2024-01-14 02:09:23
,
所有人可见
,
阅读 37
#include<bits/stdc++.h>
#define LL long long
#define x first
#define y second
#define de(x) cout<<#x<<" = "<<x<<" "
#define deg(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int N=110;
int n,m,k;
int g[N][N],st[N],match[N];
typedef pair<int,int> PII;
bool find(int x)
{
for(int i=1;i<=m;i++)
{
if(!st[i]&&g[x][i])
{
st[i]=1;
int t=match[i];
if(t==-1||find(t))
{
match[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
while(cin>>n,n)
{
cin>>m>>k;
memset(g,0,sizeof g);
for(int i=1;i<=k;i++)
{
int t,a,b;
cin>>t>>a>>b;
if(!a||!b)continue;
g[a][b]=1;
}
memset(match,-1,sizeof match);
int res=0;
for(int i=1;i<=n;i++)
{
memset(st,0,sizeof st);
if(find(i))res++;
}
cout<<res<<endl;
}
return 0;
}