Pagini recente » Cod sursa (job #1007675) | Cod sursa (job #1619964) | Cod sursa (job #1423640) | Cod sursa (job #1702549) | Cod sursa (job #1247845)
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
const int NMAX = 10005;
bool vis[NMAX];
vector <int> graph[NMAX];
int pereche[NMAX];
int pair_up (int node) {
if(vis[node])
return 0;
vis[node] = 1;
for(vector <int>::iterator it = graph[node].begin(); it != graph[node].end(); ++ it)
if(!pereche[*it] || pair_up(pereche[*it])) {
pereche[*it] = node;
return 1;
}
return 0;
}
int main() {
freopen("cuplaj.in", "r", stdin);
freopen("cuplaj.out", "w", stdout);
int i, n, m, e, x, y, ans;
scanf("%d%d%d", &n, &m, &e);
for(i = 1; i <= e; ++ i) {
scanf("%d%d", &x, &y);
graph[x].push_back(y);
}
ans = 0;
for(i = 1; i <= n; ++ i) {
memset(vis, 0, sizeof(vis));
ans += pair_up(i);
}
printf("%d\n", ans);
for(i = 1; i <= m; ++ i)
if(pereche[i])
printf("%d %d\n", pereche[i], i);
return 0;
}