标签:
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5040 Accepted Submission(s): 2430
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int map[350][350], dis[350], vis[350]; 6 int n, u; 7 bool Search(int a){ 8 for(int i = 1; i <= u; i++){ 9 if(map[a][i] && !vis[i]){ 10 vis[i] = 1; 11 if(!dis[i] || Search(dis[i])){ 12 dis[i] = a; 13 return true; 14 } 15 } 16 } 17 return false; 18 } 19 int main(){ 20 int t; 21 scanf("%d", &t); 22 while(t--){ 23 scanf("%d %d", &n, &u); 24 memset(map, 0, sizeof(map)); 25 memset(dis, 0, sizeof(dis)); 26 for(int i = 1; i <= n; i++){ 27 int a, b; 28 scanf("%d", &a); 29 for(int j = 1; j <= a; j++){ 30 scanf("%d", &b); 31 map[i][b] = 1; 32 } 33 } 34 int cnt = 0; 35 for(int i = 1; i <= n; i++){ 36 memset(vis, 0, sizeof(vis)); 37 if(Search(i)) 38 cnt++; 39 } 40 printf(cnt==n?"YES\n":"NO\n"); 41 } 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4743500.html