poj 3041
来源:互联网 发布:淘宝运营是什么工作 编辑:程序博客网 时间:2024/05/21 04:41
二分图匹配
#include <iostream>#include <vector>#include <cstring>using namespace std;const int MAX_N = 505;const int MAX_K = 10005;int n, k, V;int r[MAX_K], c[MAX_K];int match[MAX_K];bool used[MAX_K];vector<int> G[MAX_K];void add_edge(int u, int v) {G[u].push_back(v);G[v].push_back(u);}bool dfs(int v) {used[v] = true;for(int i=0; i<G[v].size(); i++) {int u = G[v][i], w = match[u];if(w<0 || !used[w] && dfs(w)) {match[v] = u;match[u] = v;return true;}}return false;}int bipartite_matching() {int res = 0;memset(match, -1, sizeof(match));for(int v=0; v<V; v++) {if(match[v] < 0) {memset(used, 0, sizeof(used));if(dfs(v))res++;}}return res;}void solve() {V = 2 * n;for(int i=0; i<k; i++)add_edge(r[i]-1, n+c[i]-1);printf("%d\n", bipartite_matching());}int main() {scanf("%d%d", &n, &k);for(int i=0; i<k; i++)scanf("%d%d", &r[i], &c[i]);solve();return 0;}
0 0
- POJ 3041 POJ 3041
- POJ 3041
- poj 3041
- POJ 3041
- poj.3041
- poj-3041
- poj 3041
- poj 3041
- poj 3041
- poj 3041
- POJ 3041
- poj 3041
- POJ-3041
- 【POJ】3041
- POJ 3041 Asteroids
- poj 3041 Asteroids
- poj 3041 匈牙利算法
- poj 3041(匈牙利)
- PHP基础教程十三之反射、对象序列化
- Python package 管理工具pip安装
- js的事件分类和相关介绍
- java 计算包含中文字符串的真实长度
- Android 线程池详解
- poj 3041
- WebLogic(12C)—NetWork Channel
- Android应用程序分类
- Hadoop2.x分布式安装以及HA部署
- apache启动端口被占用解决办法
- 交叉编译过程中遇到的问题总结
- iOS10环境下,横屏调用相机,首次会询问是否允许,点击允许后会出现卡屏现象,这个是系统问题吗?
- java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
- DOS下的一些操作命令