Pagini recente » Cod sursa (job #932550) | Cod sursa (job #1776429) | Cod sursa (job #2324175) | Cod sursa (job #3142670) | Cod sursa (job #2841213)
#include <bits/stdc++.h>
#define ull unsigned long long
#define FILES freopen("cuplaj.in","r",stdin);\
freopen("cuplaj.out","w",stdout);
#define CMAX 1000000
#define fastio std::ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
#define mp make_pair
#define INF 999999999999999
#define mod 1000000007
#define ll long long
#define MAX 80000
#define SMAX 500000
#define pb push_back
#define add emplace_back
#define void inline void
using namespace std;
int n,m,e,matched[MAX+5],matched2[MAX+5];
bool ok[MAX+5];
vector<int> v[MAX+5];
bool cuplaj(int x)
{
if(ok[x]) return 0;
ok[x] = 1;
for(auto i : v[x])
{
if(!matched[i])
{
matched[i] = x;
matched2[x] = i;
return 1;
}
}
for(auto i : v[x])
{
if(cuplaj(matched[i]))
{
matched[i] = x;
matched2[x] = i;
return 1;
}
}
return 0;
}
int main()
{
fastio
FILES
cin >> n >> m >> e;
for(int i = 1; i <= e; ++i)
{
int a,b;
cin >> a >> b;
v[a].add(b);
}
int tot = 0;
while(1)
{
memset(ok,false,sizeof(ok));
int gd = 0;
for(int i = 1;i <= n; ++i){
int l = cuplaj(i);
gd |= l;
tot += l;
}
if(!gd) break;
}
cout << tot << '\n';
for(int i = 1;i <= n; ++i)
{
if(matched2[i]) cout << i << ' ' << matched2[i] << '\n';
}
}