POJ 1274 The Perfect Stall
作者:互联网
题目链接:POJ 1274 The Perfect Stall
题目大意:
题解:
二分图匹配模板。
#include <cstring>
#include <iostream>
using namespace std;
#define io_speed_up ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int n, m, link[210], ans;
bool vis[210], g[210][210];
bool hungry(int now) {
for (int i = 1; i <= n; i++) {
if (!vis[i] && g[now][i]) {
vis[i] = true;
if (!link[i] || hungry(link[i])) {
link[i] = now;
return true;
}
}
}
return false;
}
int main() {
io_speed_up;
while (cin >> n >> m) {
memset(g, 0, sizeof(g));
memset(link, 0, sizeof(link));
for (int i = 1, s, x; i <= n; ++i) {
cin >> s;
while (s--) {
cin >> x;
g[i][x] = true;
}
}
ans = 0;
for (int i = 1; i <= n; ++i) {
memset(vis, 0, sizeof(vis));
ans += hungry(i);
}
cout << ans << endl;
}
return 0;
}
标签:Perfect,210,int,memset,1274,cin,Stall,link 来源: https://www.cnblogs.com/IzumiSagiri/p/15857569.html