-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11375.cpp
57 lines (53 loc) · 897 Bytes
/
11375.cpp
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;
int n, m;
vector<int> p[1001];
int emp[1001];
int job[1001];
bool v[1001];
bool match(int a) {
// a = employer no
if (a == 0 || v[a]) {
return false;
}
v[a] = true;
for (int j = 0; j < p[a].size(); j++) {
int jobnum = p[a].at(j);
if (job[jobnum] == a) continue;
if (job[jobnum] == 0 || match(job[jobnum])) {
emp[a] = jobnum;
job[jobnum] = a;
return true;
}
}
return false;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int c, ci;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> c;
while (c--) {
cin >> ci;
p[i].push_back(ci);
}
emp[i] = 0;
}
for (int i = 1; i <= m; i++) {
job[i] = 0;
}
int answer = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
v[j] = false;
}
if (match(i)) {
answer++;
}
}
cout << answer;
}