HDU - 1054 Strategic Game
Posted ruthank
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 1054 Strategic Game相关的知识,希望对你有一定的参考价值。
二分图匹配模板题
#include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdin); #define FOPO freopen("out.txt", "w", stdout); using namespace std; typedef long long LL; const int maxn = 1500 + 1000; int n, k, x, y; int link[maxn], vis[maxn]; vector<int> v[maxn]; void build(int x, int y) { v[x].push_back(y), v[y].push_back(x); } bool dfs(int k) { int sz = v[k].size(); for (int i = 0; i < sz; i++) { if (!vis[v[k][i]]) { vis[v[k][i]] = 1; if (link[v[k][i]] == -1 || dfs(link[v[k][i]])) { link[v[k][i]] = k; return true; } } } return false; } int hungary() { int u; int res = 0; memset(link, -1, sizeof(link)); for (int i = 0; i < n; i++) { memset(vis, 0, sizeof(vis)); if (dfs(i)) res++; } return res; } int main() { while(~scanf("%d", &n)) { for (int i = 0; i < n; i++) v[i].clear(); for (int i = 1; i <= n; i++) { scanf("%d:(%d)", &x, &k); for (int j = 1; j <= k; j++) scanf("%d", &y), build(x, y), build(y, x); } printf("%d\n", hungary()/2); } }
以上是关于HDU - 1054 Strategic Game的主要内容,如果未能解决你的问题,请参考以下文章