Pagini recente » Cod sursa (job #2308809) | Istoria paginii runda/ne-auzim | Cod sursa (job #1629059) | Cod sursa (job #2486733) | Cod sursa (job #554190)
Cod sursa(job #554190)
#include <vector>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#define N_MAX 10011
#define oo 1<<20
using namespace std;
int N, M;
bool was[N_MAX];
int L[N_MAX], R[N_MAX];
vector< int > G[N_MAX], v;
inline bool Check( int x )
{
if( was[x] )
return false;
was[x]=true;
vector< int >::const_iterator it=G[x].begin(), iend=G[x].end();
for( ; it < iend; ++it )
if( !R[*it] || Check( R[*it] ) )
{
L[x]=*it;
R[*it]=x;
return true;
}
return false;
}
int main( void )
{
int E, x, y, maxMatch=0;
vector< int >::const_iterator it, iend;
ifstream in( "cuplaj.in" );
for( in>>N>>M>>E; E; --E )
{
in>>x>>y;
G[x].push_back(y);
v.push_back(x);
}
iend=v.end();
for( it=v.begin(); it < iend; ++it )
if( !L[*it] )
{
fill( was, was+N+1, false );
if( Check(*it) )
++maxMatch;
}
else ++maxMatch;
ofstream out( "cuplaj.out" );
out<<maxMatch<<'\n';
for( it=v.begin(); it < iend && maxMatch; ++it )
if( L[*it] )
{
out<<*it<<' '<<L[*it]<<'\n';
--maxMatch;
}
return EXIT_SUCCESS;
}