标签:
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8863 Accepted Submission(s): 4077
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int map[1010][1010], dis[1010], vis[1010]; 6 int n; 7 bool Dfs(int a) 8 { 9 for(int i = 0; i < n; i++) 10 { 11 if(map[a][i] && !vis[i]) 12 { 13 vis[i] = 1; 14 if(!dis[i] || Dfs(dis[i])) 15 { 16 dis[i] = a; 17 return true; 18 } 19 } 20 } 21 return false; 22 } 23 int main() 24 { 25 int q, m, GG; 26 while(~scanf("%d", &n)) 27 { 28 memset(map, 0, sizeof(map)); 29 memset(dis, 0, sizeof(dis)); 30 for(int i = 0; i < n; i++) 31 { 32 scanf("%d: (%d)", &q, &m); 33 for(int i = 1; i <= m; i++) 34 { 35 scanf("%d", &GG); 36 map[q][GG] = 1; 37 } 38 } 39 int sum = 0; 40 for(int i = 0; i < n; i++) 41 { 42 memset(vis, 0, sizeof(vis)); 43 if(Dfs(i)) 44 sum++; 45 } 46 printf("%d\n", n - sum/2); 47 } 48 return 0; 49 }
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int map[1010][1010], dis[1010], vis[1010]; 6 int n; 7 bool Dfs(int a) 8 { 9 for(int i = 0; i < n; i++) 10 { 11 if(map[a][i] && !vis[i]) 12 { 13 vis[i] = 1; 14 if(!dis[i] || Dfs(dis[i])) 15 { 16 dis[i] = a; 17 return true; 18 } 19 } 20 } 21 return false; 22 } 23 int main() 24 { 25 int q, m, GG; 26 while(~scanf("%d", &n)) 27 { 28 memset(map, 0, sizeof(map)); 29 memset(dis, 0, sizeof(dis)); 30 for(int i = 0; i < n; i++) 31 { 32 scanf("%d: (%d)", &q, &m); 33 for(int i = 1; i <= m; i++) 34 { 35 scanf("%d", &GG); 36 map[q][GG] = 1; 37 } 38 } 39 int sum = 0; 40 for(int i = 0; i < n; i++) 41 { 42 memset(vis, 0, sizeof(vis)); 43 if(Dfs(i)) 44 sum++; 45 } 46 printf("%d\n", n - sum/2); 47 } 48 return 0; 49 }
杭电1068--Girls and Boys(二分图最大独立集)
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4746260.html