Pagini recente » Cod sursa (job #1404556) | Borderou de evaluare (job #1036104) | Cod sursa (job #127112) | Cod sursa (job #1575145) | Cod sursa (job #3040845)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f ("felinare.in");
ofstream g ("felinare.out");
int n,m,rasp;
vector<int>adiacenta[8201];
bool viz[8201];
int st[8201],dr[20001];
bool cuplaj(int nod)
{
if(viz[nod] == 1)
return 0;
viz[nod] = 1;
for(auto x:adiacenta[nod])
{
if(dr[x]==0)
{
dr[x] = nod;
st[nod]=x;
return 1;
}
}
for(auto x:adiacenta[nod])
{
if(cuplaj(dr[x]))
{
dr[x] = nod;
st[nod] = x;
return 1;
}
}
return 0;
}
int main()
{
f >> n>> m;
for(int i = 1;i<=m;i++)
{
int x,y;
f >>x >> y;
adiacenta[x].push_back(y);
}
bool change = 1;
while(change)
{
change = 0;
for(int i= 1;i<=8201;i++)
{
viz[i] = 0;
}
for(int i= 1;i<=n;i++)
{
if(st[i] == 0)
{
if(cuplaj(i))
{
change = 1;
}
}
}
}
for(int i = 1;i<=n;i++)
{
if(st[i]!=0)
rasp++;
}
rasp = 2*n-rasp;
g << rasp;
}