HDU 2063 过山车

这是一道裸的二分匹配题:

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

using namespace std;

int visit[524],partner[524],K,N,M,G[524][524];

bool path( int num )

{

   for( int i = 1 ; i <= N ; i++ )

   {

       if( G[num][i] == 1 && visit[i]==0 )

       {

             visit[i]  = 1;

             if( partner[i] == 0 || path( partner[i] ) )

            {

                partner[i] = num; 

                return true;    

            }        

       }        

   } 

   return false;    

}

int main(  )

{

    int x,y;

    while( scanf( "%d",&K ),K )

    {

        memset( G , 0 , sizeof( G ) );

        memset( partner , 0 , sizeof( partner ) );

        scanf( "%d %d",&M,&N );

        for( int i =1; i <= K; i++ )

        {

            scanf( "%d %d",&x ,&y );

            G[x][y] = 1;    

        }    

        int ans = 0;

        for( int i = 1 ; i <= M ; i++ )

        {

            memset( visit , 0, sizeof( visit ) );

             if( path( i ) )

                 ans ++;

        }

        printf( "%d\n",ans );

    }

    //system( "pause" );

    return 0;

}

 

你可能感兴趣的:(HDU)