Pagini recente » Cod sursa (job #2940674) | Cod sursa (job #140440) | Cod sursa (job #2970403) | Cod sursa (job #1642260) | Cod sursa (job #2405289)
#include <cstring>
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream fin ( "cuplaj.in");
ofstream fout ("cuplaj.out");
using namespace std;
const int Dim = (1e5+ 5) * 2;
vector < int > G[Dim];
int n,m,e,L[Dim],R[Dim],maxmat,Viz[Dim];
bool Cupleaza(int x) {
if ( Viz[x] ) return false;
Viz[x] = true;
for ( const auto & y : G[x] )
if( !R[y] or Cupleaza(R[y])) {
R[y] = x;
L[x] = y;
return true;
}
return false;
}
int main() {
fin >> n >> m >> e;
int x,y;
for ( ; e > 0; --e) {
fin >> x >> y;
G[x].push_back(n+y);
}
bool ok = true;
while ( ok ) {
ok = false;
memset(Viz,0,sizeof(Viz));
for( int i = 1; i <= n; ++i)
if ( !L[i] and Cupleaza(i)) {
ok = true;
++maxmat;
}
}
fout << maxmat << "\n";
for ( int i = 1; i <= n; ++i)
if ( L[i])
fout << i << " " << L[i]-n << "\n";
}