Pagini recente » Cod sursa (job #2593499) | Cod sursa (job #1241383) | Cod sursa (job #3350859) | Cod sursa (job #2593485) | Cod sursa (job #3329916)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("adlic.in");
ofstream fout("adlic.out");
int n, m, q, i, rasp;
vector<int> gr[10002];
int cup[10002];
bool viz[10002];
static inline bool Cupleaza(int nod) {
for(int vec : gr[nod]) {
if(viz[vec]) continue;
viz[vec] = true;
if(cup[vec] == 0 || Cupleaza(cup[vec])) {
cup[vec] = nod;
return true;
}
}
return false;
}
int main() {
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n >> m >> q;
for(i = 1; i <= q; i++) {
int x, y;
fin >> x >> y;
y += n;
gr[x].push_back(y);
//gr[y].push_back(x);
}
for(i = 1; i <= n; i++) {
memset(viz, false, sizeof(viz));
if(Cupleaza(i)) rasp++;
}
fout << rasp << "\n";
for(i = n + 1; i <= n + m; i++) {
if(cup[i]) fout << cup[i] << " " << i - n << "\n";
}
return 0;
}