Pagini recente » Cod sursa (job #1966989) | Cod sursa (job #2884586) | Cod sursa (job #119794) | Cod sursa (job #548173) | Cod sursa (job #2737791)
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
ifstream fin ("cuplaj.in");
ofstream fout ("cuplaj.out");
bool viz[10002];
int st[10002], dr[10002], n,m, e;
vector<int>G[10002];
bool match (int nod) {
if (viz[nod])
return 0;
viz[nod] = 1;
for (auto it : G[nod])
if (!dr[it] || match(dr[it])) {
st[nod] = it;
dr[it] = nod;
return 1;
}
return 0;
}
int main()
{
fin >> n >> m >> e;
while (e--) {
int x, y;
fin >> x >> y;
G[x].push_back(y);
}
bool ok = 1;
while (ok) {
ok = 0;
memset(viz, 0, sizeof(viz));
for (int i = 1; i <= n; i++)
if (!st[i] && match(i))
ok = 1;
}
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] << "\n";
return 0;
}