Pagini recente » Cod sursa (job #1274271) | Cod sursa (job #581324) | Cod sursa (job #939071) | Cod sursa (job #1682013) | Cod sursa (job #2858042)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e4;
vector <int> edges[2 * NMAX + 1];
int viz[2 * NMAX + 1];
int match[2 * NMAX + 1];
bool bfs( int node ) {
viz[node] = 1;
for ( auto it : edges[node] ) {
int x = match[it];
if ( x == 0 ) {
match[node] = it;
match[it] = node;
return 1;
}
if ( !viz[x] && bfs( x ) ) {
match[node] = it;
match[it] = node;
return 1;
}
}
return 0;
}
int cuplaj( int n ) {
int cnt = 0, ok = 1;
while ( ok ) {
ok = 0;
memset( viz, 0, sizeof(viz) );
// memset( match, 0, sizeof(match) );
for ( int i = 1; i <= n; i ++ ) {
if ( !viz[2 * i - 1] && !match[2 * i - 1] && bfs( 2 * i - 1 ) ) {
cnt ++;
ok = 1;
}
}
}
return cnt;
}
int main() {
ifstream fin( "felinare.in" );
ofstream fout( "felinare.out" );
int n, m, i, a, b;
fin >> n >> m;
for ( i = 0; i < m; i ++ ) {
fin >> a >> b;
edges[2 * a].push_back( 2 * b - 1 );
edges[2 * b - 1].push_back( 2 * a );
// cout << 2 * a << ' ' << 2 * b - 1 << endl;
}
fout << 2 * n - cuplaj( n ) << '\n';
return 0;
}