Pagini recente » Cod sursa (job #1446716) | Cod sursa (job #1622606) | Cod sursa (job #3233408) | Cod sursa (job #2225096) | Cod sursa (job #448719)
Cod sursa(job #448719)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on May 4, 2010, 2:21 PM
*/
#include <vector>
#include <cstdlib>
#include <fstream>
#include <algorithm>
#define Nmax 10011
/*
*
*/
using namespace std;
bool uz[Nmax];
int L[Nmax], R[Nmax];
vector< int > G[Nmax];
inline bool PairUp( int x )
{
if( uz[x] )
return false;
uz[x]=true;
vector< int >::iterator it=G[x].begin(), iend=G[x].end();
for( ; it < iend; ++it )
if( !R[*it] || PairUp( R[*it] ) )
{
L[x]=*it;
R[*it]=x;
return true;
}
return false;
}
int main(int argc, char** argv)
{
bool was;
int N, M, E, x, y, nrc=0;
ifstream in( "cuplaj.in" );
for( in>>N>>M>>E; E; --E )
{
in>>x>>y;
G[x].push_back(y);
}
while( true )
{
was=true;
fill( uz+1, uz+N+1, false );
for( x=1; x <= N; ++x )
if( !L[x] && PairUp(x) )
was=false, ++nrc;
if( was )
break;
}
ofstream out( "cuplaj.out" );
out<<nrc<<'\n';
for( x=1; nrc && x <= N; ++x )
if( L[x] )
out<<x<<' '<<L[x]<<'\n', --nrc;
return (EXIT_SUCCESS);
}