Pagini recente » Cod sursa (job #2769321) | Cod sursa (job #2896588) | Cod sursa (job #179779) | Cod sursa (job #551233) | Cod sursa (job #2636567)
#include<bits/stdc++.h>
using namespace std;
const int NMAX=10005;
vector<int> G[NMAX];
int n,ans;
int st[NMAX],dr[NMAX],viz[NMAX];
bool cupleaza(int nod){
if(viz[nod])
return false;
viz[nod]=true;
for(auto it: G[nod])
if(!dr[it]){
st[nod]=it;
dr[it]=nod;
return true;
}
for(auto it: G[nod])
if(cupleaza(dr[it])){
st[nod]=it;
dr[it]=nod;
return true;
}
return false;
}
void solve(){
bool gata=0;
while(!gata){
gata=1;
for(int i=1;i<=n;i++)
viz[i]=0;
for(int i=1;i<=n;i++)
if(!st[i] && cupleaza(i)){
ans++;
gata=0;
}
}
}
int main(){
freopen("cuplaj.in","r",stdin);
freopen("cuplaj.out","w",stdout);
int m,e;
scanf("%d%d%d", &n, &m, &e);
while(e--){
int x,y;
scanf("%d%d", &x, &y);
G[x].push_back(y);
}
solve();
printf("%d\n", ans);
for(int i=1;i<=n;i++)
if(st[i])
printf("%d %d\n", i, st[i]);
return 0;
}