forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1140 - Courses.cpp
executable file
·63 lines (49 loc) · 1.22 KB
/
1140 - Courses.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
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int MAXV1 = 100;
const int MAXV2 = 300;
vector<int> L[MAXV1];
bool visited[MAXV2];
int V1,V2,match[MAXV2];
bool dfs(int u){
for(int i=L[u].size()-1;i>=0;--i){
int v = L[u][i];
if(!visited[v]){
visited[v] = true;
if(match[v]==-1 || dfs(match[v])){
match[v] = u;
return true;
}
}
}
return false;
}
int maximum_matching(){
int ans = 0;
memset(match,-1,sizeof(match));
for(int i=0;i<V1;++i){
memset(visited,false,sizeof(visited));
ans += dfs(i);
}
return ans;
}
int main(){
int T,m,s;
scanf("%d",&T);
while(T--){
scanf("%d %d",&V1,&V2);
for(int i=0;i<V1;++i) L[i].clear();
for(int i=0;i<V1;++i){
scanf("%d", &m);
while(m--){
scanf("%d",&s);
L[i].push_back(s-1);
}
}
if(maximum_matching()==V1) printf("YES\n");
else printf("NO\n");
}
return 0;
}