-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2188.cpp
51 lines (47 loc) · 827 Bytes
/
2188.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
#include <iostream>
#include <vector>
using namespace std;
int n, m;
vector<int> want[201];
int cow[201];
int home[201];
bool v[201];
bool gohome(int cownum) {
if (cownum == 0 || v[cownum]) {
return false;
}
v[cownum] = true;
for (int i = 0; i < want[cownum].size(); i++) {
int wh = want[cownum].at(i); // wanthome
if (home[wh] == 0 || gohome(home[wh])) {
cow[cownum] = wh;
home[wh] = cownum;
return true;
}
}
return false;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int s, si;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s;
while (s--) {
cin >> si;
want[i].push_back(si);
}
}
int answer = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
v[j] = false;
}
if (gohome(i)) {
answer++;
}
}
cout << answer;
}