Pagini recente » Cod sursa (job #605967) | Cod sursa (job #1713806) | Cod sursa (job #464403) | Cod sursa (job #576533) | Cod sursa (job #1414992)
#include <iostream>
#include <fstream>
#include <vector>
#define nmax 10001
using namespace std;
bool seen[nmax];
int nL, nR, m, x, y, sol, L[nmax], R[nmax];
vector <int> v[nmax];
bool match(int x) {
if(seen[x]) return false;
seen[x] = true;
for(auto y:v[x])
if(!R[y] || match(R[y]))
return true;
return false;
}
int main() {
ifstream f("cuplaj.in");
ofstream g("cuplaj.out");
f>>nL>>nR>>m;
for(int i=1; i<=m; i++) {
f>>x>>y;
v[x].push_back(y);
}
bool ok = true;
while(ok) {
ok = false;
memset(seen, 0, sizeof(seen));
for(int i=1; i<=nL; i++)
if(!L[i] && match(i)) {
sol++;
ok = true;
}
}
for(int i=1; i<=nL; i++)
if(L[i]) g<<i<<" "<<L[i]<<"\n";
return 0;
}