-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11375.cpp
More file actions
48 lines (40 loc) · 681 Bytes
/
Copy path11375.cpp
File metadata and controls
48 lines (40 loc) · 681 Bytes
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
#include <cstdio>
using namespace std;
int n, m;
bool g[1001][1001];
int g_n[1001], g_m[1001];
int sol;
bool b[1001];
bool dfs(int start) {
if (b[start])
return false;
b[start] = true;
for (int i = 1; i <= m; i++) {
if (g[start][i]) {
if (!g_m[i] || dfs(g_m[i])) {
g_m[i] = start;
g_n[start] = i;
return true;
}
}
}
return false;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1, x, y; i <= n; i++) {
scanf("%d", &x);
for (int j = 1; j <= x; j++) {
scanf("%d", &y);
g[i][y] = true;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
b[j] = false;
if (dfs(i))
sol++;
}
printf("%d", sol);
return 0;
}