Cod sursa(job #2841130)

Utilizator LXGALXGA a LXGA Data 29 ianuarie 2022 12:26:31
Problema Cuplaj maxim in graf bipartit Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.29 kb
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;
ifstream cin("cuplaj.in");
ofstream cout("cuplaj.out");
int getcode(string x)
{
	if (x == "XS")
		return 1;
	if (x == "S")
		return 2;
	if (x == "M")
		return 3;
	if (x == "L")
		return 4;
	if (x == "XL")
		return 5;
	if (x == "XXL")
		return 6;
}
int t, n, m, mt[7], e, x, y;
bool use[31];
string a, b;
vector<int> g[31];
vector<pair<int, int>> ans;
bool matching(int nod)
{
	if (use[nod])
		return 0;
	use[nod] = 1;
	for (int i : g[nod])
	{
		if (mt[i] == 0 || matching(mt[i]))
		{
			mt[i] = nod;
			return 1;
		}
	}
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	t = 1;
	while (t--)
	{
		cin >> n >> m >> e;
		for (int i = 1; i <= e; i++)
		{
			cin >> x >> y;
			g[x].push_back(y);
		}
		/*for (int i = 1; i <= m; i++)
		{
			cin >> a >> b;
			g[i].push_back(getcode(a));
			g[i].push_back(getcode(b));
		}*/
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
				use[j] = 0;
			matching(i);
		}
		for (int i = 1; i <= m; i++)
		{
			if (mt[i])
				ans.push_back({ mt[i],i });
		}
		cout << ans.size() << '\n';
		for (auto i : ans)
			cout << i.first << ' ' << i.second << '\n';
	}
	return 0;
}