Pagini recente » Cod sursa (job #24733) | Cod sursa (job #1639080) | Cod sursa (job #1232353) | Cod sursa (job #2466853) | Cod sursa (job #2709577)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
const int NMAX = 10000;
vector<int> G[2*NMAX + 1];
int viz[2*NMAX + 1], p[2*NMAX + 1];
int path( int node ) {
if( viz[node] )
return 0;
viz[node] = 1;
for( const auto &it : G[node] ) {
if( !p[it] || path(p[it]) ) {
p[node] = it;
p[it] = node;
return 1;
}
}
return 0;
}
int main() {
int n, m, e;
fin>>n>>m>>e;
for( int i = 1; i <= e; i ++ ) {
int x, y;
fin>>x>>y;
G[x].push_back(y + n);
G[y + n].push_back(x);
}
int cuplaj = 0, gasit;
do{
gasit = 0;
memset(viz, 0, sizeof(viz));
for( int i = 1; i <= n; i ++ ) {
if( !p[i] && path(i) ) {
cuplaj ++;
gasit = 1;
}
}
}while( gasit );
fout<<cuplaj<<"\n";
for( int i = 1; i <= n; i ++ )
if( p[i] )
fout<<i<<" "<<p[i] - n<<"\n";
return 0;
}