Cod sursa(job #2617172)

Utilizator drknss_Hehe hehe drknss_ Data 20 mai 2020 21:25:53
Problema Flux maxim Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.54 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const double lil = 0.0000000000001;
const ll INF64 = 3e18 + 1;
const int N = 2e4 + 11;

ifstream in("cuplaj.in");
ofstream out("cuplaj.out");

int n,m,e,viz[N],ans,l[N],r[N];

vector<int>v[N];

bool fnd(int nod){

    if(viz[nod])return 0;

    viz[nod] = 1;

    for(auto it : v[nod]){

        if(!r[it] || fnd(r[it])){
            l[nod] = it;
            r[it] = nod;
            return 1;
        }
    }

    return 0;
}

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

    in >> n >> m >> e;

    for(int i = 1; i <= e; i++){
        int x,y;
        in >> x >> y;
        v[x].push_back(y);
    }

    int yes = 1;
    while(yes){

        yes = 0;

        memset(viz,0,sizeof(viz));

        for(int i = 1; i <= n; i++){
            if(!l[i] && fnd(i)){
                yes = 1;
                ans++;
            }
        }
    }

    out << ans << '\n';

    for(int i = 1; i <= n; i++){
        if(!l[i])continue;
        out << i << ' ' << l[i] << '\n';
    }

return 0;
}