Pagini recente » Cod sursa (job #1201841) | Cod sursa (job #418294) | Cod sursa (job #1103789) | Cod sursa (job #488495) | Cod sursa (job #2604129)
#include <bits/stdc++.h>
#define NMAX 10005
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
vector<int> G[2 * NMAX];
int st[2 * NMAX], dr[2 * NMAX];
bool viz[NMAX];
bool cup(int nod)
{
viz[nod] = 1;
for(auto it: G[nod])
if(!dr[it])
{
st[nod] = it;
dr[it] = nod;
return 1;
}
for(auto it: G[nod])
if(!viz[dr[it]] && cup(dr[it]))
{
st[nod] = it;
dr[it] = nod;
return 1;
}
return 0;
}
int main()
{
int n, m, k;
fin >> n >> m >> k;
for(int i = 1; i <= k; ++i)
{
int x, y;
fin >> x >> y;
G[x].push_back(y + NMAX);
G[y + NMAX].push_back(x);
}
int ok = 1;
while(ok)
{
ok = 0;
memset(viz, 0, sizeof(viz));
for(int i = 1; i <= n; ++i)
if(!viz[i] && !st[i])
ok |= cup(i);
}
int cnt = 0;
for(int i = 1; i <= n; ++i)
if(st[i])
++cnt;
fout << cnt << '\n';
for(int i = 1; i <= n; ++i)
if(st[i])
fout << i << ' ' << st[i] - NMAX << '\n';
return 0;
}