标签:book integer pac cts ems win form inf should
C/C++:
1 #include <map> 2 #include <queue> 3 #include <cmath> 4 #include <vector> 5 #include <string> 6 #include <cstdio> 7 #include <cstring> 8 #include <climits> 9 #include <iostream> 10 #include <algorithm> 11 #define INF 0xffffff 12 using namespace std; 13 const int my_max = 1005; 14 15 int n, m, a, b, my_G[my_max][my_max], my_book[my_max], my_right[my_max]; 16 17 bool my_dfs(int x) 18 { 19 for (int i = 0; i < n; ++ i) 20 { 21 if (my_G[x][i] && !my_book[i]) 22 { 23 my_book[i] = 1; 24 if (!my_right[i] || my_dfs(my_right[i])) 25 { 26 my_right[i] = x; 27 return true; 28 } 29 } 30 } 31 return false; 32 } 33 34 int my_hungarian() 35 { 36 int my_cnt = 0; 37 for (int i = 0; i < n; ++ i) 38 { 39 memset (my_book, 0, sizeof(my_book)); 40 if (my_dfs(i)) 41 ++ my_cnt; 42 } 43 return my_cnt / 2; 44 } 45 46 int main() 47 { 48 while (~scanf("%d", &n)) 49 { 50 memset(my_right, 0, sizeof(my_right)); 51 memset(my_G, 0, sizeof(my_G)); 52 for (int i = 0; i < n; ++ i) 53 { 54 scanf("%d: (%d)", &a, &m); 55 while (m --) 56 { 57 scanf("%d", &b); 58 my_G[a][b] = 1; 59 } 60 } 61 62 printf("%d\n", n - my_hungarian()); 63 } 64 return 0; 65 }
hdu 1068 Girls and Boys (最大独立集)
标签:book integer pac cts ems win form inf should
原文地址:https://www.cnblogs.com/GetcharZp/p/9462268.html