Pagini recente » Cod sursa (job #18318) | Cod sursa (job #1201739) | Cod sursa (job #1441780) | Cod sursa (job #1464619) | Cod sursa (job #2720476)
#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[it] = node;
p[node] = it;
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 gasit, cuplaj = 0;
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;
}