Pagini recente » Cod sursa (job #2285728) | Cod sursa (job #2448384) | Cod sursa (job #213619) | Cod sursa (job #2364753) | Cod sursa (job #412366)
Cod sursa(job #412366)
#include <queue>
#include <vector>
#include <fstream>
#define Nmax 10001
/*
*
*/
using namespace std;
int sink;
int C[Nmax][Nmax];
vector< vector< int > > G;
vector< int >::const_iterator it, iend;
int find_path( void )
{
int x;
queue< int > Q;
vector< int > father( sink+1, -1 );
Q.push( 0 );
while( -1 == father[sink] && !Q.empty() )
{
x=Q.front(); Q.pop();
for( it=G[x].begin(), iend=G[x].end(); it < iend; ++it )
if( -1 == father[*it] && C[x][*it] > 0 )
{
father[*it]=x;
Q.push( *it );
}
}
if( -1 == father[sink] )
return 0;
father[0]=-1;
for( x=sink; -1 != father[x]; x=father[x] )
{
C[father[x]][x]-=1;
C[x][father[x]]+=1;
}
return 1;
}
int MaxBipartitMach( void )
{
int s;
for( s=0; find_path(); ++s );
return s;
}
int main( void )
{
int N, M, E, x, y;
ifstream in( "cuplaj.in" );
in>>N>>M>>E;
sink=max( N, M )+1;
G.resize( sink+1 );
for( ; E; --E )
{
in>>x>>y;
C[0][x]=C[y][sink]=C[x][y]=C[y][x]=1;
G[0].push_back( x );
G[x].push_back( 0 );
G[x].push_back( x );
G[y].push_back( y );
G[y].push_back( sink );
G[sink].push_back( y );
}
ofstream out( "cuplaj.out" );
out<<MaxBipartitMach();
return 0;
}