AcWing 376. 机器任务
原题链接
简单
作者:
ZTEG
,
2020-02-01 20:03:25
,
所有人可见
,
阅读 1256
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int a,b,c;
int ans;
bool book[105][105];
bool used[105];
int belong[105];
bool find(int x)
{
for(int i=1;i<=m;i++)
{
if(book[x][i]&&!used[i])
{
used[i]=1;
if(!belong[i]||find(belong[i]))
{
belong[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
while(1)
{
ans=0;
memset(book,0,sizeof(book));
memset(belong,0,sizeof(belong));
cin>>n;
if(!n)
return 0;
cin>>m>>k;
while(k--)
{
scanf("%d %d %d",&a,&b,&c);
book[b][c]=1;
}
for(int i=1;i<=n;i++)
{
memset(used,0,sizeof(used));
if(find(i))
ans++;
}
cout<<ans<<endl;
}
}