#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
#define N 1005
int link[N], vis[N];
vector<int> v[N];
int n, m, k;
int dfs( int u )
{
for( int i = 0; i < v[u].size(); i++ )
{
int to = v[u][i];
if( !vis[to] )
{
vis[to] = 1;
if( link[to] == -1 || dfs( link[to] ) )
{
link[to] = u;
return 1;
}
}
}
return 0;
}
int main()
{
while(~scanf("%d", &n))
{
if( n == 0 )
break;
scanf("%d%d", &m, &k);
for( int i = 0; i < n; i ++ )
v[i].clear();
int i, z, x;
while( k-- )
{
scanf("%d%d%d", &i, &z, &x);
if( z && x )
v[z].push_back(x);
}
memset(link, -1, sizeof(link));
int ans = 0;
for( int i = 0; i < n; i++)
{
memset( vis, 0, sizeof( vis ));
ans += dfs( i );
}
printf("%d\n", ans);
}
return 0;
}
hdu 1150 Machine Schedule
最新推荐文章于 2020-11-24 12:47:06 发布