Pagini recente » Cod sursa (job #1635659) | Cod sursa (job #1777758) | Cod sursa (job #2213175) | Cod sursa (job #183681) | Cod sursa (job #2905637)
#include <bits/stdc++.h>
#define ull unsigned long long
#define FILES freopen("cuplaj.in","r",stdin);\
freopen("cuplaj.out","w",stdout);
#define CMAX 15485863
#define fastio std::ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
#define mp make_pair
#define INF 1e18
#define mod 666013
#define ll long long
#define SMAX 65000000
#define MAX 10000
#define pb push_back
#define add emplace_back
#define void inline void
using namespace std;
vector<int>v[MAX+5];
int n,m,ed,a,b,go[MAX+5],ans[MAX+5];
bool ok = 1, check[MAX+5], okk[MAX+5];
bool Good(int x)
{
if(check[x]) return 0;
check[x] = 1;
for(auto i : v[x])
{
if(!go[i])
{
okk[x] = 1;
go[i] = x;
ans[x] = i;
return 1;
}
}
for(auto i : v[x])
{
if(Good(go[i]))
{
okk[x] = 1;
go[i] = x;
ans[x] = i;
return 1;
}
}
return 0;
}
int main()
{
fastio
FILES
cin >> n >> m >> ed;
for(int i = 1;i <= ed; ++i)
cin >> a >> b, v[a].add(b);
while(ok)
{
for(int i = 1;i <= n; ++i) check[i] = 0;
ok = 0;
for(int i = 1;i <= n; ++i){
if(!okk[i])
ok |= Good(i);
}
}
int ANS = 0;
for(int i = 1;i <= n; ++i)
if(ans[i]) ANS++;
cout << ANS << '\n';
for(int i = 1;i <= n; ++i)
if(ans[i]) cout << i << ' ' << ans[i] << '\n';
}