Pagini recente » Rating Uta Vlad (vladuta61) | Cod sursa (job #2330830) | Cod sursa (job #2314059) | Cod sursa (job #1533871) | Cod sursa (job #2244914)
#include <bits/stdc++.h>
#define Nmax 10002
using namespace std;
ifstream f("cuplaj.in");
ofstream g("cuplaj.out");
int n,m,c,st[2*Nmax],dr[2*Nmax],a,b,nr;
bool uz[Nmax];
vector<int> v[2*Nmax];
bool cup(int nod){
uz[nod] = 1;
for (auto it : v[nod]){
if (!dr[it]){
dr[it] = nod;
st[nod] = it;
return 1;
}
}
for (auto it : v[nod]){
if (!uz[dr[it]] && cup(dr[it])){
dr[it] = nod;
st[nod] = it;
return 1;
}
}
return 0;
}
int main()
{
ios::sync_with_stdio(false);
f >> n >> m >> c;
for (int i=1;i<=c;i++){
f >> a >> b;
v[a].push_back(b+Nmax);
v[b+Nmax].push_back(a);
}
int ok = 1;
while(ok){
ok = 0;
memset(uz,0,sizeof(uz));
for (int i=1;i<=n;i++)
if (!st[i] && !uz[i]) ok |= cup(i);
}
for (int i=1;i<=n;i++) if (st[i]) nr++;
g << nr << '\n';
for (int i=1;i<=n;i++) if (st[i]) g << i << ' ' << st[i] - Nmax << '\n';
return 0;
}