Pagini recente » Cod sursa (job #682131) | Cod sursa (job #1294125) | Cod sursa (job #227678) | Cod sursa (job #13268) | Cod sursa (job #1790595)
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 66013;
int L[Nmax], R[Nmax], Left, Right, m;
vector<int> G[Nmax];
bitset<Nmax> used;
bool cuplaj(int k)
{
if(used[k])
return 0;
used[k] = 1;
for(auto it : G[k])
if(L[it] == 0) {
R[k] = it;
L[it] = k;
return true;
}
for(auto it : G[k])
if(cuplaj(L[it]))
{
R[k] = it;
L[it] = k;
return true;
}
return 0;
}
int main()
{
freopen("cuplaj.in","r",stdin);
freopen("cuplaj.out","w",stdout);
cin.sync_with_stdio(false);
cin >> Left >> Right >> m;
for(int i = 1; i <= m; ++i)
{
int a,b;
cin >> a >> b;
G[a].push_back(Left + b);
G[Left + b].push_back(a);
}
int result = 0;
bool notDone = true;
while(notDone) {
notDone = false;
used = 0;
for(int i = 1; i <= Left; ++i)
if(!R[i] && cuplaj(i))
{
++result;
notDone = true;
}
}
cout << result << "\n";
for(int i = 1; i <= Left; ++i)
if(R[i])
cout << i << " " << R[i] - Left << "\n";
return 0;
}