Pagini recente » Istoria paginii runda/oji2021 | Istoria paginii runda/simulare-cartita-28 | Istoria paginii runda/oniwtf/clasament | Istoria paginii runda/ojiliis/clasament | Cod sursa (job #473456)
Cod sursa(job #473456)
#include <fstream>
#include <vector>
using namespace std;
const int MAXN = 10000;
vector <int> G [ MAXN ];
int n, m, e, l [ MAXN ], r [ MAXN ], u [ MAXN ];
int match ( const int nd ){
if ( u [ nd ] ) return 0;
else u [ nd ] = true;
vector < int > :: iterator it;
for ( it = G [ nd ] . begin (); it != G [ nd ] . end (); ++ it )
if ( ! r [ * it ] ){
l [ nd ] = * it;
r [ * it ] = nd;
u [ * it ] =true;
return 1;
}
for ( it = G [ nd ] . begin (); it != G [ nd ] . end (); ++ it )
if ( match ( r [ * it ] ) ){
l [ nd ] = * it;
r [ * it ] = nd;
u [ * it ] =true;
return 1;
}
return 0;
}
int main(){
int i, x, y, cuplaj = 0;
ifstream f ( "cuplaj.in" );
ofstream g ( "cuplaj.out" );
f >> n >> m >> e;
while( e -- ){
f >> x >> y;
G [ x ] . push_back ( y );
}
for ( i = 1; i <= n; ++ i )
if ( ! l [ i ] ){
if ( match ( i ) )
cuplaj ++;
else{
memset ( u, 0, sizeof(u) );
cuplaj += match ( i );
}
}
g << cuplaj << '\n';
for ( i = 1; i <= n; ++ i )
if ( l [ i ] )
g << i << ' ' << l [ i ] << '\n';
g . close ();
return 0;
}