-
Notifications
You must be signed in to change notification settings - Fork 0
/
11375.cpp
47 lines (42 loc) · 863 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
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> edges[1005];
int b[1005];
int visited[1005];
bool dfs(int idx) {
if (visited[idx]) return false;
visited[idx] = 1;
for (int i : edges[idx]) {
if (b[i] == -1 || dfs(b[i])) {
b[i] = idx;
return true;
}
}
return false;
}
int b_match() {
memset(b, -1, sizeof(b));
int cnt = 0;
for (int i = 1; i <= N; i++) {
memset(visited, 0, sizeof(visited));
if (dfs(i)) cnt++;
}
return cnt;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
int t, w;
cin >> t;
while (t--) {
cin >> w;
edges[i].push_back(w);
}
}
cout << b_match();
return 0;
}