标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 19760 | Accepted: 7784 |
Description
Input
Output
Sample Input
2 3 3 3 1 2 3 2 1 2 1 1 3 3 2 1 3 2 1 3 1 1
Sample Output
YES NO
Source
#include <cstdio> #include <cstring> using namespace std; int p, n, left[305]; bool g[105][305], v[305]; bool dfs(int x) { for (int i = 1; i <= n; ++i) if (g[x][i] && v[i]) { v[i] = false; if (left[i] == 0 || dfs(left[i])) { left[i] = x; return true; } } return false; } int main() { int Test; scanf("%d", &Test); while (Test--) { scanf("%d%d", &p, &n); memset(g, false, sizeof(g)); for (int i = 1; i <= p; ++i) { int num, x; scanf("%d", &num); while (num--) { scanf("%d", &x); g[i][x] = true; } } int ans = 0; memset(left, 0, sizeof(left)); for (int i = 1; i <= p; ++i) { memset(v, true, sizeof(v)); if (dfs(i)) ans++; } printf("%s\n", ans == p ? "YES" : "NO"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/albert7xie/p/4906695.html