Pagini recente » Cod sursa (job #1077745) | Cod sursa (job #640166) | Cod sursa (job #1275223) | Cod sursa (job #2839617) | Cod sursa (job #1698518)
#include <fstream>
#include <list>
#include <bitset>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
int a,b,x,y,A[10010],B[10010],i,j,n,m,c;
bitset <10010> fv;
list <int> GA[ 10010 ];
bool cuplaj( int nod )
{
if( fv[ nod ] == 1 )
return false;
fv[ nod ] = 1;
for( auto it : GA[ nod ] )
if( B[ it ] == 0 )
{
A[ nod ] = it;
B[ it ] = nod;
return true;
}
for( auto it : GA[ nod ] )
if( cuplaj( B[ it ] ) )
{
A[ nod ] = it;
B[ it ] = nod;
return true;
}
return false;
}
int main()
{
fin>>a>>b>>m;
for( i = 1 ; i <= m ; i++ )
{
fin>>x>>y;
GA[ x ].push_back( y );
}
for( i = 1 ; i <= a ; i++ )
{
if( A[ i ] == 0 && cuplaj( i ) )
{
++c;
fv = 0;
}
}
fout<<c<<'\n';
for( i = 1 ; i <= a ; i++ )
if( A[ i ] )
fout<<i<<' '<<A[ i ]<<'\n';
return 0;
}