标签:ffffff 0ms climits imu inf code lines ring set
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 26239 | Accepted: 14182 |
Description
Input
Output
Sample Input
3 4 1 1 1 3 2 2 3 2
Sample Output
2
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 = 505; 14 15 int n, k, a, b, my_ans, my_line[my_max][my_max], my_book[my_max], my_right[my_max]; 16 17 bool my_dfs(int x) 18 { 19 for (int i = 1; i <= n; ++ i) 20 { 21 if (!my_book[i] && my_line[x][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 main() 35 { 36 while (~scanf("%d%d", &n, &k)) 37 { 38 my_ans = 0; 39 memset(my_line, 0, sizeof(my_line)); 40 memset(my_right, 0, sizeof(my_right)); 41 42 while (k --) 43 { 44 scanf("%d%d", &a, &b); 45 my_line[a][b] = 1; 46 } 47 for (int i = 1; i <= n; ++ i) 48 { 49 memset(my_book, 0, sizeof(my_book)); 50 if (my_dfs(i)) my_ans ++; 51 } 52 53 printf("%d\n", my_ans); 54 } 55 return 0; 56 }
标签:ffffff 0ms climits imu inf code lines ring set
原文地址:https://www.cnblogs.com/GetcharZp/p/9466419.html