Pagini recente » Cod sursa (job #3147798) | Cod sursa (job #1882846) | Cod sursa (job #1633832) | Cod sursa (job #2180476) | Cod sursa (job #3042083)
#include <bits/stdc++.h>
#define MMAX 100//08
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
bool cuplat[MMAX];
int match[MMAX];
vector <bool> used(MMAX);
vector <int> G[MMAX];
bool DFS(int node) {
if(used[node]) return false;
used[node] = true;
for(auto x : G[node])
if(!match[x] || DFS(match[x])) {
match[x] = node;
cuplat[node] = true;
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
fin.tie(NULL); fout.tie(NULL);
int n, m, e; fin >> n >> m >> e;
for(int i = 1; i <= e; i ++) {
int u, v; fin >> u >> v;
G[u].push_back(v);
}
bool found = false;
while(!found) {
found = true;
used = vector <bool> (MMAX, 0);
for(int i = 1; i <= n; i ++)
if(!cuplat[i]) found = !DFS(i);
}
int ans = 0;
for(int i = 1; i <= m; i ++) ans += (match[i] != 0);
fout << ans << '\n';
for(int i = 1; i <= m; i ++)
if(match[i] != 0) fout << i << ' ' << match[i] << '\n';
return 0;
}