[BOJ] 11375 열혈강호

열혈강호

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
#include <bits/stdc++.h>

#define MAX_N 1001
#define ll long long
#define all(a) begin(a), end(a)
using namespace std;

ll n, m;
ll match[MAX_N], seen[MAX_N];
vector<int> job[MAX_N];
ll dfs(ll u, ll s) {
for(auto& v : job[u]) {
if(seen[v] == s) continue;
seen[v] = s;
if(match[v] == -1 or dfs(match[v], s)) {
match[v] = u;
return 1;
}
}
return 0;
}
ll solve() {
ll res = 0;
for(ll i = 1; i <= n; i++) {
if(dfs(i,i))
res++;
}
return res;
}

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
memset(match, -1, sizeof(match));
for(ll i = 1, w, j; i <= n; i++) {
cin>>w;
while(w--) {
cin>>j;
job[i].push_back(j);
}
}
cout<<solve();
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/04/21/PS/BOJ/11375/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.