博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 2444 The Accomodation of Studentsp[二分图判定,匈牙利算法]
阅读量:5051 次
发布时间:2019-06-12

本文共 1551 字,大约阅读时间需要 5 分钟。

There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other. 
Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don't know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room. 
Calculate the maximum number of pairs that can be arranged into these double rooms. 

InputFor each data set: 

The first line gives two integers, n and m(1<n<=200), indicating there are n students and m pairs of students who know each other. The next m lines give such pairs. 
Proceed to the end of file. 
OutputIf these students cannot be divided into two groups, print "No". Otherwise, print the maximum number of pairs that can be arranged in those rooms. 
Sample Input

4 41 21 31 42 36 51 21 31 42 53 6

Sample Output

No3 点染色判定二分图,将二分图分成2个部分,之后匈牙利求最大匹配即可。
1 #include
2 using namespace std; 3 #include
4 #include
5 #include
6 const int maxn = 1000; 7 vector
maps[maxn]; 8 int n,m; 9 int ok[maxn];//ok[i]代表第i个节点可否配对 10 int matched[maxn];//matched[i]代表第i个节点的配对对象; 11 bool match(int x){12 for(int i=0;i

 

转载于:https://www.cnblogs.com/xfww/p/8542342.html

你可能感兴趣的文章
OA项目设计的能力③
查看>>
Cocos2d-x3.0 文件处理
查看>>
全面整理的C++面试题
查看>>
Activity和Fragment生命周期对比
查看>>
android 分辨率自适应
查看>>
查找 EXC_BAD_ACCESS 问题根源的方法
查看>>
日常报错
查看>>
list-style-type -- 定义列表样式
查看>>
mysql-1045(28000)错误
查看>>
Ubuntu 编译出现 ISO C++ 2011 不支持的解决办法
查看>>
1.jstl c 标签实现判断功能
查看>>
Linux 常用命令——cat, tac, nl, more, less, head, tail, od
查看>>
VueJS ElementUI el-table 的 formatter 和 scope template 不能同时存在
查看>>
Halcon一日一练:图像拼接技术
查看>>
iOS设计模式 - 中介者
查看>>
centos jdk 下载
查看>>
HDU 1028 Ignatius and the Princess III(母函数)
查看>>
(转)面向对象最核心的机制——动态绑定(多态)
查看>>
token简单的使用流程。
查看>>
django创建项目流程
查看>>