#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#define INF 0x7fffffff
using namespace std;
const int MOD = 1e9 + 7;
const int N = 100 + 10;
const int M = 300 + 10;
int n,m;
int vis[M], match[M];
int G[N][M];
bool dfs(int u) {
for(int v = 0; v < m; v++) {
if(vis[v] || !G[u][v]) continue;
vis[v] = true;
if(match[v] == -1 || dfs(match[v])) {
match[v] = u;
return true;
}
}
return false;
}
int maxmatch() {
int cnt = 0;
memset(match, -1, sizeof(match));
for(int i = 0; i < n; i++) {
memset(vis, false, sizeof(vis));
if(dfs(i)) cnt++;
}
return cnt;
}
int main() {
int T;
scanf("%d", &T);
while(T--) {
memset(G, 0, sizeof(G));
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++) {
int cnt, s;
scanf("%d", &cnt);
while(cnt--) {
scanf("%d", &s);
s--;
G[i][s] = 1;
}
}
int ans = maxmatch();
if(ans == n) puts("YES");
else puts("NO");
}
return 0;
}
POJ1469——COURSES(二分图最大匹配模板)
最新推荐文章于 2019-04-11 21:59:38 发布