Pku 1274 The Perfect Stall

Pku 1274 The Perfect Stall
#include  < stdio.h >
#include 
< string .h >
#include 
< stdlib.h >

#define  N 210

bool  map[N][N];
int   chk[N];
int   match[N];
int   m,n;

int  dfs(  int  p )
{
    
forint i= 0; i< m; ++i )
        
if( map[p][i] && !chk[i] )
        
{
            chk[i]
= 1;
            
int t= match[i];
            match[i]
= p;
            
            
if( t== -1  || dfs(t) ) return 1;
            match[i]
= t;
        }

        
    
return 0;
}



int  Match()
{
    
int res= 0;
    
    
forint i= 0; i< n; ++i )
    
{
        memset( chk, 
falsesizeof(chk) );
        
        
if( dfs(i) ) res++;
    }

    
    
return res;
}


int  main()
{
    
while( scanf("%d%d"&n,&m)!= EOF )
    
{
        memset( map, 
falsesizeof(map) );
        memset( match, 
-1sizeof(match) );
        
        
forint i= 0; i< n; ++i )
        
{
            
int t;
            scanf(
"%d"&t);
            
            
forint j= 0; j< t; ++j )
            
{
                
int d;
                scanf(
"%d",&d);
                
                map[i][d
-1]= true;
            }

        }

        
        printf(
"%d\n", Match() );
    }

    
    
return 0;
}

        

你可能感兴趣的:(Pku 1274 The Perfect Stall)