📄 2472.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 2472 on 2007-04-16 at 11:08:04 */
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 128;
const int INF = 1 << 28;
class Graph {
private:
bool map[N][N], check[N];
int n, match[N];
bool dfs(int);
public:
int maxMatch();
bool solve();
};
bool Graph::dfs(int p) {
for(int i = 0; i < n; i++) {
if(!check[i] && map[p][i]) {
check[i] = true;
int t = match[i];
match[i] = p;
if(t == -1 || dfs(t)) return true;
match[i] = t;
}
}
return false;
}
int Graph::maxMatch() {
memset(match, -1, sizeof(match));
int mth = 0;
for(int i = 0; i < n; i++) {
memset(check, false, sizeof(check));
if(dfs(i)) mth++;
}
return mth;
}
bool Graph::solve() {
int a, b; scanf("%d %d", &a, &b);
if(a == 0) exit(0);
n = max(a, b);
memset(map, false, sizeof(map));
for(int i = 0; i < b; i++) {
int m; scanf("%d", &m);
for(int j = 0; j < m; j++) {
int c; scanf("%d", &c);
map[i][c] = true;
}
}
return maxMatch() == a;
}
Graph g;
int main()
{
while(true) printf("%s\n", g.solve() ? "yes" : "no");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -