poj1325最小顶点覆盖
来源:互联网 发布:显卡性能数据图 编辑:程序博客网 时间:2024/05/16 09:04
//因为要完成所有的任务每个任务是一条线//因为机器A和B任一个做该任务就算完成了//那么这题的模型就是覆盖所以的边的最少的顶点数目//那么就是最小顶点覆盖问题//注意机器开始就在0上所有跟0的边可以删除#include <iostream>#include <string.h>#include <stdio.h>#include <vector>using namespace std;#define MAX_N 1010static vector<int>G[1010];static int V;static bool used[MAX_N];static int match[MAX_N];static void add_edge(int from,int to){G[from].push_back(to);G[to].push_back(from);}static 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[u] = v;match[v] = u;return true;}}return false;}static int hungary(int n){int res = 0;memset(match,-1,sizeof(match));for (int i=0;i<V;++i){if (i==0||i==n) continue;if (match[i]<0){memset(used,0,sizeof(used));if (dfs(i))res++;}}return res;}int main(){int n,m,k;while(scanf("%d",&n)&&n){scanf("%d %d",&m,&k);int p,u,v;for (int i=0;i<MAX_N;++i) G[i].clear();for (int i=0;i<k;++i){scanf("%d %d %d",&p,&u,&v);if (u==0||v==0)//开始就在0模式所以不用换 continue;add_edge(u,v+n);}V = n+m;printf("%d\n",hungary(n));}return 0;}
0 0
- poj1325(最小顶点覆盖)
- poj1325最小顶点覆盖
- poj1325 最小顶点覆盖 konig定理
- poj1325 Machine Schedule【最小顶点覆盖】
- poj1325——Machine Schedule//最小顶点覆盖
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
- POJ1325.Machine Schedule机器调度——最小顶点覆盖
- poj1325——Machine Schedule(最小顶点覆盖)
- poj1325最小点覆盖
- poj1325 二分图的最小点覆盖
- poj1325 二分图的最小覆盖
- poj1325 Machine Schedule 最小点覆盖
- poj3041(最小顶点覆盖)
- HDU1150最小顶点覆盖
- POJ3041 最小顶点覆盖
- POJ3041 最小顶点覆盖
- 树的最小顶点覆盖
- HDU 1054 最小顶点覆盖
- UVA 10269Adventure of Super Mario 【最短路 + dp】
- 关于windows系统下eclipse开发NDK,是否还需要cygwin的问题
- 【POJ 1276】Cash Machine
- PDO对象之query()方法
- sqlite删除数据时主键不能更新
- poj1325最小顶点覆盖
- 决定学JAVA了
- UIViewController
- C#学习之Do-While循环
- 史上最简单的Ubuntu上搭建java和Android开发环境
- 杭电1162Eddy's picture(最小生成树)
- Linux下菜单编辑配置
- cocos2dx基础篇——音乐音效SimpleAudioEngine
- 云计算网络虚拟化学习笔记-私有网络