Pagini recente » Cod sursa (job #559517) | Cod sursa (job #1529782) | Cod sursa (job #2150027) | Cod sursa (job #3030793) | Cod sursa (job #2526696)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
const int nmax = 10005;
int n, m, e;
vector <int> g[nmax];
int viz[nmax], st[nmax], dr[nmax];
int ok, ans;
inline bool check(int nod)
{
if (viz[nod])
return false;
viz[nod] = 1;
for (auto it : g[nod])
{
if (dr[it] == 0)
{
st[nod] = it;
dr[it] = nod;
return true;
}
}
for (auto it : g[nod])
{
if (check(dr[it]))
{
st[nod] = it;
dr[it] = nod;
return true;
}
}
return false;
}
int main()
{
fin >> n >> m >> e;
while (e--)
{
int a, b;
fin >> a >> b;
g[a].push_back(b);
}
ok = 1;
while (ok)
{
ok = 0;
for (int i = 1; i <= n; i++)
viz[i] = 0;
for (int i = 1; i <= n; i++)
if (!st[i] && check(i))
{
ans++;
ok = 1;
}
}
fout << ans << "\n";
for (int i = 1; i <= n; i++)
if (st[i])
fout << i << " " << st[i] << "\n";
return 0;
}