Pagini recente » Cod sursa (job #2083513) | Cod sursa (job #142192) | Cod sursa (job #774772) | Cod sursa (job #2968297) | Cod sursa (job #448702)
Cod sursa(job #448702)
/*
* 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=true;
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( was )
{
was=false;
fill( uz+1, uz+N+1, false );
for( x=1; x <= N; ++x )
if( !L[x] && PairUp(x) )
++nrc, was=true;
}
ofstream out( "cuplaj.out" );
out<<nrc<<'\n';
for( x=1; x <= N; ++x )
if( L[x] )
out<<x<<' '<<L[x]<<'\n';
return (EXIT_SUCCESS);
}