#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<stdio.h> #include<stdlib.h> using namespace std; #define N 500 int n1, n2, ans; int result[N]; bool state[N]; bool map[N][N]; bool find(int x) { for (int i = 1; i <= n2; ++i){ if (map[x][i] && !state[i]){ state[i] = true; if (result[i] == 0 || find(result[i])){ result[i] = x; return true; } } } return false; } int hungary() { for (int i = 1; i <= n1; ++i){ memset(state, 0, sizeof(state)); if (find(i)) ++ans; } return ans; } int main() { int t, p, n; int a, b; scanf("%d", &t); while (t--){ memset(map, 0, sizeof(map)); memset(result, 0, sizeof(result)); ans = 0; scanf("%d %d", &p, &n); for (int i = 1; i <= p; ++i){ scanf("%d", &a); for (int j = 1; j <= a; ++j){ scanf("%d", &b); map[i][b] = true; } } n1 = p; n2 = n; //cout << hungary() << endl; if (p == hungary()) cout << "YES" << endl; else cout << "NO" << endl; } }
时间: 2024-10-19 09:50:21