-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1037.cpp
More file actions
51 lines (51 loc) · 1.09 KB
/
Copy path1037.cpp
File metadata and controls
51 lines (51 loc) · 1.09 KB
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 <cstdio>
#include <iostream>
using namespace std;
// 这题使用了匈牙利算法,代码比较简洁,和直接使用网络流相比
bool match(int i, int N, int* p, bool* vis, int Map[51][51])
{
for (int j = 1; j <= N; ++j)
if (Map[i][j] && !vis[j])
{
vis[j] = true;
if (p[j] == 0 || match(p[j], N, p, vis, Map))
{
p[j] = i;
return true;
}
}
return false;
}
int main()
{
int T;
cin >> T;
for (int t = 0;t < T;t++)
{
int n, m;
cin >> n >> m;
int Map[51][51] = {};
for (int i = 1;i <= n;i++)
{
int k;
cin >> k;
for (int j = 0;j < k;j++)
{
int l;
cin >> l;
Map[i][l] = 1;
}
}
int p[51] = {};
int result = 0;
for (int i = 1;i <= n;i++)
{
bool vis[51] = {};
if (match(i, m, p, vis, Map))
{
result++;
}
}
cout << result << endl;
}
}