Pagini recente » Cod sursa (job #2144007) | Cod sursa (job #1728742) | Cod sursa (job #1531060) | Cod sursa (job #3193536) | Cod sursa (job #1442598)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define dim 8191
int n,m;
bool come[dim*2+4],go[dim*2+4],seen[dim*2+4];
vector<int> Adj[dim+2];
int L[dim*2+4],R[dim*2+4];
bool cuplaj(int x)
{
if(seen[x]) return
false;
seen[x] = 1;
for(auto p: Adj[x]) {
if(!L[p] || cuplaj(p)) {
R[x] = p;
L[p] = x;
return true;
}
}
return false;
}
int main()
{
ifstream fin("felinare.in");
ofstream fout("felinare.out");
fin >> n >> m;
int a,b;
for(int i = 1; i <= m; i++) {
fin >> a >> b;
Adj[a].push_back(b+n);
go[a] = true;
come[b] = true;
}
int Sol = 2*n;
int C = 0;
bool ok = true;
while(ok) {
ok = false;
for(int i = 1; i <= 2*n; i++)
seen[i] = false;
for(int i = 1; i <= n; i++) {
if(!R[i] && cuplaj(i)) {
--Sol;
ok = true;
}
}
}
fout << Sol << "\n";
}