include iostream include vector using namespace std vector int vector

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<vector>
using namespace std;
vector<int> m;
vector<bool> used;
vector< vector<int> > g;
bool tru_kunn(int v)
{
used[v] = true;
for (int i = 0; i < g[v].size(); ++i)
{
int to = g[v][i];
if (m[to] == -1 || (!used[m[to]] && tru_kunn(m[to]) ))
{
m[to] = v;
return true;
}
}
return false;
}
int main()
{
int q, n, k, a, b;
cin >> q >> n >> k;
m.resize(q, -1);
g.resize(n);
used.resize(n);
for (int i = 0; i < k; ++i)
{
cin >> a >> b;
g[b - 1].push_back(a - 1);
}
for (int i = 0; i < n; ++i)
{
used.clear();
used.resize(n, false);
tru_kunn(i);
}
int mp = 0;
for (int i = 0; i < q; ++i)
{
if (m[i] != -1)
mp++;
}
cout << q + n - mp << endl;
return 0;
}