bzoj 1191

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 #define fi first
 4 #define se second
 5 #define mk make_pair
 6 #define pii pair<int,int>
 7 
 8 using namespace std;
 9 
10 const int N=2000+7;
11 const int M=1e4+7;
12 const int inf=0x3f3f3f3f;
13 const LL INF=0x3f3f3f3f3f3f3f3f;
14 const int mod=1e9 + 7;
15 
16 int n, m, vis[N], match[N];
17 bool edge[N][N];
18 
19 int path(int u) {
20     for(int v = 1; v <= n; v++) {
21         if(edge[u][v] && !vis[v]) {
22             vis[v] = 1;
23             if(match[v] == -1 || path(match[v])) {
24                 match[v] = u;
25                 return 1;
26             }
27         }
28     }
29     return 0;
30 }
31 
32 int main() {
33     memset(match, -1, sizeof(match));
34     scanf("%d%d", &n, &m);
35     for(int i = 1; i <= m; i++) {
36         int x, y; scanf("%d%d", &x, &y);
37         x++, y++;
38         edge[i][x] = edge[i][y] = 1;
39     }
40     int ans = 0;
41     for(int i = 1; i <= m; i++) {
42         memset(vis, 0, sizeof(vis));
43         if(path(i)) ans++;
44         else break;
45     }
46     printf("%d\n", ans);
47     return 0;
48 }

猜你喜欢

转载自www.cnblogs.com/CJLHY/p/9003217.html
今日推荐