Pagini recente » Cod sursa (job #1539305) | Cod sursa (job #2153539) | Cod sursa (job #2213255) | Cod sursa (job #1320160) | Cod sursa (job #2216760)
#include <bits/stdc++.h>
using namespace std;
ifstream in("cuplaj.in");
ofstream out("cuplaj.out");
int n, m, e, x, y, cnt, L[10010], R[10010];
vector <int> v[10010];
bool viz[10010];
bool OMG_I_HAVE_A_PARTNER(int from){
if(viz[from])
return 0;
viz[from] = 1;
for(auto to : v[from]){
if(R[to] == 0){
L[from] = to;
R[to] = from;
return 1;
}
if(OMG_I_HAVE_A_PARTNER(R[to]) == 1){
L[from] = to;
R[to] = from;
return 1;
}
}
return 0;
}
int main(){
in >> n >> m >> e;
for(int i = 1; i <= e; i++){
in >> x >> y;
v[x].push_back(y);
}
bool flag = 1;
while(flag){
memset(viz, 0, sizeof viz);
flag = 0;
for(int i = 1; i <= n; i++)
if(L[i] == 0 && OMG_I_HAVE_A_PARTNER(i)){
flag = 1;
cnt++;
}
}
out << cnt;
for(int i = 1; i <= n; i++)
if(L[i] != 0)
out << '\n' << i << ' ' << L[i];
return 0;
}