Pagini recente » Cod sursa (job #1689162) | Cod sursa (job #3273797) | Cod sursa (job #2847477) | Cod sursa (job #2831573) | Cod sursa (job #2523463)
#include <bits/stdc++.h>
#define NM 10005
using namespace std;
ifstream fin ("cuplaj.in");
ofstream fout ("cuplaj.out");
void read();
int n, m, e, ma[NM], cmax;
vector<int> v[NM];
set<int> L, R;
bitset<NM> viz;
bool find_match(int nod)
{
if(viz[nod])
return 0;
viz[nod] = 1;
for(auto it:v[nod])
if(!ma[it] || (ma[it] && find_match(ma[it])))
{
ma[nod] = it;
ma[it] = nod;
return 1;
}
return 0;
}
int main()
{
read();
bool ok = 1;
while(ok)
{
ok = 0;
for(int i=1; i<=n; i++)
viz[i] = 0;
for(auto it:L)
if(!ma[it] && find_match(it))
ok = 1;
}
for(auto it:L)
if(ma[it])
cmax++;
fout << cmax << '\n';
for(auto it:L)
if(ma[it])
fout << it << ' ' << ma[it]-n+m << '\n';
return 0;
}
void read()
{
fin >> n >> m >> e;
while(e--)
{
int x, y;
fin >> x >> y;
y+=n;
L.insert(x);
R.insert(y);
v[x].push_back(y);
v[y].push_back(x);
}
n+=m;
}