Pagini recente » Cod sursa (job #2599551) | Cod sursa (job #3162460) | Cod sursa (job #894301) | Cod sursa (job #3237224) | Cod sursa (job #1923377)
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
ifstream fin( "cuplaj.in" );
ofstream fout( "cuplaj.out" );
int a[2010],b[2010],i,j,n,m,fv[1010],q,x,y,ans;
vector< int > G[ 2010 ];
bool cuplaj( int nod )
{
if( fv[ nod / 8 ] & 1 << ( nod % 8 ) )
return false;
fv[ nod / 8 ] += 1<<( nod %8 );
for( auto it : G[ nod ] )
{
if( !b[ it ] )
{
b[ it ] = nod;
a[ nod ] = it;
return true;
}
}
for( auto it : G[ nod ] )
{
if( cuplaj( b[ it ] ) )
{
b[ it ] = nod;
a[ nod ] = it;
return true;
}
}
return false;
}
int main()
{
fin>>n>>m>>q;
for( i = 1 ; i <= q ; i++ )
{
fin>>x>>y;
G[ x ].push_back( y );
}
for( i = 1 ; i <= n ; i++ )
{
if( !a[ i ] )
{
if( cuplaj( i ) )
{
for( j = 0 ; j <= n / 8 + 2 ; j++ )
fv[ j ] = 0;
++ans;
}
}
}
fout<<ans<<'\n';
for( i = 1 ; i <= n ; i++ )
{
if( a[ i ] )
fout<<i<<' '<<a[ i ]<<'\n';
}
return 0;
}