Pagini recente » Cod sursa (job #1378819) | Cod sursa (job #3213576) | Cod sursa (job #576878) | Cod sursa (job #820274) | Cod sursa (job #2523479)
#include <bits/stdc++.h>
#define NM 10005
using namespace std;
void read();
int n, m, e, ma[2*NM], cmax;
vector<int> v[2*NM];
set<int> L, R;
bitset<2*NM> viz;
bool find_match(int nod)
{
if(viz[nod])
return 0;
viz[nod] = 1;
for(auto it:v[nod])
if(!ma[it])
{
ma[nod] = it;
ma[it] = nod;
return 1;
}
for(auto it:v[nod])
if(ma[it] && find_match(ma[it]) && ma[it]!=nod)
{
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++;
printf("%d\n", cmax);
for(auto it:L)
if(ma[it])
{
printf("%d", it);
printf(" ");
printf("%d\n", ma[it]-n+m);
}
return 0;
}
void read()
{
freopen("fmcm.in", "r", stdin);
freopen("fmcm.out", "w", stdout);
scanf("%d%d%d", &n, &m, &e);
while(e--)
{
int x, y;
scanf("%d%d", &x, &y);
y+=n;
L.insert(x);
R.insert(y);
v[x].push_back(y);
v[y].push_back(x);
}
n+=m;
}