标签:des style blog http color os strong io
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 17154 | Accepted: 6741 |
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
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <climits>
7 #include <vector>
8 #include <queue>
9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #define LL long long
13 #define INF 0x3f3f3f3f
14 using namespace std;
15 const int maxn = 310;
16 int mp[maxn][maxn],p,n;
17 int link[maxn];
18 bool used[maxn];
19 bool dfs(int u){
20 for(int i = 1; i <= n; i++){
21 if(mp[u][i] && !used[i]){
22 used[i] = true;
23 if(link[i] == -1 || dfs(link[i])){
24 link[i] = u;
25 return true;
26 }
27 }
28 }
29 return false;
30 }
31 int main(){
32 int t,temp,i,j;
33 scanf("%d",&t);
34 while(t--){
35 scanf("%d%d",&p,&n);
36 memset(mp,0,sizeof(mp));
37 for(i = 1; i <= p; i++){
38 scanf("%d",&j);
39 while(j--){
40 scanf("%d",&temp);
41 mp[i][temp] = 1;
42 }
43 }
44 int ans = 0;
45 memset(link,-1,sizeof(link));
46 for(i = 1; i <= p; i++){
47 memset(used,false,sizeof(used));
48 if(dfs(i)) ans++;
49 }
50 ans == p?puts("YES"):puts("NO");
51 }
52 return 0;
53 }
POJ 1469 COURSES,布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/crackpotisback/p/3865419.html