Pagini recente » Cod sursa (job #778355) | Cod sursa (job #2642904) | Cod sursa (job #1955136) | Cod sursa (job #479434) | Cod sursa (job #3197020)
#include <bits/stdc++.h>
#define FastIo() ios_base::sync_with_stdio(false), cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
const int nmax = 10005;
vector<int> G[nmax+1];
vector<int> used;
vector<int> mt;
int n,m,e;
int x,y;
int nr;
bool try_kuhn(int x){
if(used[x]) return false;
used[x]=true;
for(int y:G[x]){
if(mt[y]==-1 || try_kuhn(mt[y])){
mt[y]=x;
return true;
}
}
return false;
}
int main(){
freopen("cuplaj.in","r",stdin);
freopen("cuplaj.out","w",stdout);
FastIo()
cin>>n>>m>>e;
for(int i=1;i<=e;i++){
cin>>x>>y;
G[x].push_back(y);
}
bitset<nmax> used1;
mt.assign(m+1,-1);
for(int x=1;x<=n;x++){
for(int y:G[x]){
if(mt[y]==-1){
used1[y]=true;
mt[y]=x;
nr++;
break;
}
}
}
for(int x=1;x<=n;x++){
if(used1[x]) continue;
used.assign(n+1,false);
if(try_kuhn(x)) nr++;
}
cout<<nr<<'\n';
for(int i=1;i<=m;i++){
if(mt[i]!=-1)
cout<<mt[i]<<' '<<i<<'\n';
}
}