Cod sursa(job #1414992)

Utilizator h2g2Ford Prefect h2g2 Data 3 aprilie 2015 14:40:55
Problema Cuplaj maxim in graf bipartit Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#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;
}