Pagini recente » Cod sursa (job #1717497) | Borderou de evaluare (job #2011017) | Cod sursa (job #2506304) | Cod sursa (job #700909) | Cod sursa (job #1923378)
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
ifstream fin( "cuplaj.in" );
ofstream fout( "cuplaj.out" );
int a[10010],b[10010],i,j,n,m,fv[10010],q,x,y,ans;
vector< int > G[ 10010 ];
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;
}