-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11377.cpp
84 lines (81 loc) · 1.15 KB
/
11377.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stack>
using namespace std;
int N, M, K;
vector<int> node[1001];
int ans;
bool visited[1001];
int work[1001];
bool dfs(int idx)
{
if (visited[idx])
{
return false;
}
visited[idx] = true;
for (int i = 0; i < node[idx].size(); i++)
{
int nxt = node[idx][i];
if (work[nxt] == 0 || dfs(work[nxt]))
{
work[nxt] = idx;
return true;
}
}
return false;
}
void abc()
{
for (int i = 1; i <= N; i++)
{
memset(visited, false, sizeof(visited));
if (dfs(i))
{
ans++;
}
}
}
void abc2()
{
int cnt = 0;
for (int i = 1; i <= N; i++)
{
memset(visited, false, sizeof(visited));
if (dfs(i))
{
cnt++;
if (cnt == K)
{
break;
}
}
}
ans += cnt;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M >> K;
for (int i = 1; i <= N; i++)
{
int num;
cin >> num;
for (int j = 0; j < num; j++)
{
int n;
cin >> n;
node[i].push_back(n);
}
}
abc();
abc2();
cout << ans;
}