【二分图+最大匹配】北大 poj 1274 The Perfect Stall
程序员文章站
2022-04-18 13:14:58
...
/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2011 panyanyany All rights reserved. URL : http://poj.org/problem?id=1274 Name : 1274 The Perfect Stall Date : Tuesday, December 20, 2011 Time Stage : half an hour Result: 9673709 panyanyany 1274 Accepted 324K 0MS C++ 1216B 2011-12-20 21:19:16 Test Data : Review : 水题…… //----------------------------------------------------------------------------*/ #include <stdio.h> #include <string.h> #define MAXSIZE 202 int n, m ; int link[MAXSIZE] ; bool cover[MAXSIZE] ; int graph[MAXSIZE][MAXSIZE] ; bool find (int cur) { int i, j ; for (i = 1 ; i <= graph[cur][0] ; ++i) { j = graph[cur][i] ; if (cover[j] == false) { cover[j] = true ; if (!link[j] || find (link[j])) { link[j] = cur ; return true ; } } } return false ; } int main (void) { int i, j ; int sum ; while (~scanf ("%d%d", &n, &m)) { for (i = 1 ; i <= n ; ++i) { scanf ("%d", &graph[i][0]) ; for (j = 1 ; j <= graph[i][0] ; ++j) scanf ("%d", &graph[i][j]) ; } sum = 0 ; memset (link, 0, sizeof (link)) ; for (i = 1 ; i <= n ; ++i) { memset (cover, 0, sizeof (cover)) ; sum += find (i) ; } printf ("%d\n", sum) ; } return 0 ; }
上一篇: js 正则匹配 url
下一篇: 常用正则表达式