http://acm.hdu.edu.cn/showproblem.php?pid=1150
#include <iostream>
#include <cstring>
using namespace std;
const int maxx=102;
int gra[maxx][maxx];
int cy[maxx];
int sy[maxx];
int m,n,ans,k;
int path(int u)
{
for(int v=1; v<=n; v++)
if(gra[u][v]>0&&!sy[v])
{
sy[v]=1;
if(!cy[v]||path(cy[v]))
{
cy[v]=u;
return 1;
}
}
return 0;
}
void MaxMatch()
{
ans=0;
memset(cy,0,sizeof(cy));
for(int i = 1; i<=m; i++)
{
memset(sy,0,sizeof(sy))
ans+=path(i);
}
}
int main()
{
while(cin>>m&&m)
{
memset(gra,0,sizeof(gra));
cin>>n>>k;
while(k--)
{
int a,b,c;
cin>>a>>b>>c;
gra[b][c]=1;
}
MaxMatch();
cout<<ans<<endl;
}
}