//两道大水……哦不 两道结论题

结论:二部图的最小覆盖数=二部图的最大匹配数

有向图的最小覆盖数=节点数-二部图的最大匹配数

 //hdu 1150
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; int n,m,k;
int f[][];
int link[];
bool adj[];
bool used[]; bool work(int x){
for (int i=;i<m;i++){
if (f[x][i] && adj[i]==false){
adj[i]=true;
if (!used[i] || work(link[i])){
link[i]=x;
used[i]=;
//printf("%d %d\n",x,i);
return true;
}
}
}
return false;
} int main(){
while (scanf("%d%d%d",&n,&m,&k)==){
memset(f,,sizeof(f));
memset(used,,sizeof(used));
for (int i=;i<k;i++){
int x,y,z;
scanf("%d%d%d",&z,&x,&y);
if (x!= && y!=){
f[x][y]=;
}
}
int ans=;
for (int i=;i<n;i++){
memset(adj,,sizeof(adj));
if (work(i)) ans++;
}
//for (int i=1;i<m;i++) printf("%d %d\n",i,link[i]);
printf("%d\n",ans);
}
return ;
}
/*
5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0
*/
 //hdu 1151
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; int T;
int n,m;
bool f[][];
int link[];
bool adj[];
bool used[]; bool work(int x){
for (int i=;i<=n;i++){
if (f[x][i] && !adj[i]){
adj[i]=;
if (!used[i] || work(i)){
link[i]=x;
used[i]=;
return true;
}
}
}
return false;
} int main(){
scanf("%d",&T);
for (int cas=;cas<=T;cas++){
memset(used,,sizeof(used));
memset(link,,sizeof(link));
memset(f,,sizeof(f));
scanf("%d",&n);
scanf("%d",&m);
for (int i=;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
f[x][y]=;
}
int ans=n;
for (int i=;i<=n;i++){
memset(adj,,sizeof(adj));
if (work(i)) ans--;
}
printf("%d\n",ans);
}
return ;
}
/*
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
*/

hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版的更多相关文章

  1. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

  2. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  3. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  4. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  5. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  6. hdu 1150 Machine Schedule (二分匹配)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU——1150 Machine Schedule

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule

    二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...

  9. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

随机推荐

  1. C# 多线程的自动管理(线程池) 基于Task的方式

    C# 多线程的自动管理(线程池) 在多线程的程序中,经常会出现两种情况:    1. 应用程序中线程把大部分的时间花费在等待状态,等待某个事件发生,然后给予响应.这一般使用 ThreadPool(线程 ...

  2. 【LeetCode练习题】Swap Nodes in Pairs

    Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exam ...

  3. JAVA Grammar Corrector

    1. Integer.MAX_VALUE, Integer.MIN_VALUE 2. int[] res = {1,2} can only be used in the initialization, ...

  4. No.26

    "信是未见之事的实底,是所望之事的确据".

  5. ExtJS+ASP.NET自己定义曲线

    第一步:创建Store数据源 var myData = []; myData.push({ 'name': '1', 'Oil_Production': '30', 'Water_Injection' ...

  6. 开源 java CMS - FreeCMS1.9公布。

    FreeCMS商业版V1.9更新功能 添加Oracle数据库支持.

  7. webapi单元测试时出现的ConfigurationManager.ConnectionStrings为空错误

    这个是读取配置文件没读到的问题,解决方法很简单,把webapi的配置文件复制到单元测试项目中,并把名字改为App.config即可. 同时 ,推荐使用Unit Test Genertor来做测试,这个 ...

  8. transform的2D部分,嗯…就这个标题了。

    上一次写了transition的内容,这次就写拼写很类似的另外一个属性transform好了……我英语差这件事就不要吐槽了,下面是正文,真的: transition是过渡,transform是变换. ...

  9. W - Bitset(第二季水)

    Description Give you a number on base ten,you should output it on base two.(0 < n < 1000)      ...

  10. Bluestacks视窗界面调整及内存调整经验

    本文将分享bluestacks视窗界面调整及内存调整的经验,可以有效解决Bluestacks缓慢.卡的问题! 一.bluestacks视窗界面调整 1.进入注册表: 2.找到下图中的键值: 3.修改键 ...