Pagini recente » Cod sursa (job #2567034) | Cod sursa (job #2789962) | Cod sursa (job #142260) | Cod sursa (job #2363422) | Cod sursa (job #3295472)
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
#define int long long
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int range_rng(int l, int r)
{
return uniform_int_distribution<int>(l,r)(rng);
}
vector<int> nodes[20005];
map<int,int> mvc;
int match[20005];
bool visited[20005];
bool path(int node)
{
int nxt;
visited[node]=1;
for (auto x : nodes[node])
{
nxt=match[x];
if (nxt)
{
if (!visited[nxt] && path(nxt))
{
match[x]=node;
match[node]=x;
return 1;
}
}
else
{
match[node]=x;
match[x]=node;
return 1;
}
}
return 0;
}
signed main()
{
ifstream fin("felinare.in");
ofstream fout("felinare.out");
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,i,j,u,v,cuplaj;
bool ok;
fin >> n >> m;
for (i=1;i<=m;i++)
{
fin >> u >> v;
nodes[u].push_back(v+n);
nodes[v+n].push_back(u);
}
for (i=1;i<=n*2;i++)
match[i]=0;
ok=1;
cuplaj=0;
while (ok)
{
ok=0;
for (i=1;i<=n*2;i++)
visited[i]=0;
for (i=1;i<=n;i++)
{
if (!match[i] && !visited[i] && path(i))
{
ok=1;
cuplaj++;
}
}
}
fout << n*2-cuplaj;
return 0;
}